Exemplo n.º 1
0
    def test_attach_returns_true_when_all_jobs_have_finished_sucessfully(self):
        group = clash.JobGroup(name="mygroup", job_factory=self.test_factory)
        group.add_job(clash.JobRuntimeSpec(args=["echo", "hello"]))
        group.add_job(clash.JobRuntimeSpec(args=["echo", "world"]))
        group.run()

        result = group.wait()

        assert result
Exemplo n.º 2
0
    def test_attach_returns_false_when_a_job_has_failed(self):
        self.test_job_two.on_finish.side_effect = lambda callback: callback(1)
        group = clash.JobGroup(name="mygroup", job_factory=self.test_factory)
        group.add_job(clash.JobRuntimeSpec(args=["echo", "hello"]))
        group.add_job(clash.JobRuntimeSpec(args=["echo", "world"]))
        group.run()

        result = group.wait()

        assert not result
Exemplo n.º 3
0
    def test_job_group_is_executed(self):
        with CloudSdkIntegrationStub() as gcloud:
            job_factory = clash.JobFactory(gcloud=gcloud, job_config=TEST_JOB_CONFIG)
            group = clash.JobGroup(name="mygroup", job_factory=job_factory)
            group.add_job(clash.JobRuntimeSpec(script="echo hello"))
            group.add_job(clash.JobRuntimeSpec(script="echo world"))

            group.run()

            assert b"hello\n" in gcloud.instances[0].logs()
            assert b"world\n" in gcloud.instances[1].logs()
Exemplo n.º 4
0
    def test_runs_multiple_jobs(self):
        group = clash.JobGroup(name="mygroup", job_factory=self.test_factory)
        group.add_job(clash.JobRuntimeSpec(script="echo hello"))
        group.add_job(clash.JobRuntimeSpec(script="echo world"))

        group.run()

        self.test_job_one.run.assert_called_with(
            script="echo hello", env_vars={}, gcs_mounts={}, gcs_target={}
        )
        self.test_job_two.run.assert_called_with(
            script="echo world", env_vars={}, gcs_mounts={}, gcs_target={}
        )
Exemplo n.º 5
0
    def test_runs_a_single_job(self):
        group = clash.JobGroup(name="mygroup", job_factory=self.test_factory)
        group.add_job(clash.JobRuntimeSpec(script="echo hello"))

        group.run()

        self.test_factory.create.assert_called_with(name_prefix=f"mygroup-0")
        self.test_job_one.run.assert_called_with(
            script="echo hello", env_vars={}, gcs_mounts={}, gcs_target={}
        )
Exemplo n.º 6
0
    def test_passes_runtime_spec_to_job(self):
        group = clash.JobGroup(name="mygroup", job_factory=self.test_factory)
        group.add_job(
            clash.JobRuntimeSpec(
                args=["_"],
                env_vars={"FOO": "bar"},
                gcs_mounts={"bucket_name": "mount_dir"},
                gcs_target={"artifacts_dir", "bucket_name"},
            ))

        group.run()

        self.test_job_one.run.assert_called_with(
            args=["_"],
            env_vars={"FOO": "bar"},
            gcs_mounts={"bucket_name": "mount_dir"},
            gcs_target={"artifacts_dir", "bucket_name"},
        )