Skip to content

Commit ddbfe65

Browse files
committed
Adds a test that re-attaches a job, but to another executor instance than
the one used to create the job in the first place.
1 parent 061a190 commit ddbfe65

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

tests/_test_tools.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ def assert_completed(job: Job, status: Optional[JobStatus]) -> None:
3838
% (status.message, stdout, stderr))
3939

4040

41-
def _get_executor_instance(ep: ExecutorTestParams, job: Job) -> JobExecutor:
42-
assert job.spec is not None
43-
job.spec.launcher = ep.launcher
44-
job.spec.attributes = JobAttributes(custom_attributes=ep.custom_attributes)
41+
def _get_executor_instance(ep: ExecutorTestParams, job: Optional[Job] = None) -> JobExecutor:
42+
if job is not None:
43+
assert job.spec is not None
44+
job.spec.launcher = ep.launcher
45+
job.spec.attributes = JobAttributes(custom_attributes=ep.custom_attributes)
4546
return JobExecutor.get_instance(ep.executor, url=ep.url)

tests/test_executor.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ def test_attach(execparams: ExecutorTestParams) -> None:
4545
assert_completed(job2, status)
4646

4747

48+
def test_attach2(execparams: ExecutorTestParams) -> None:
49+
job = Job(JobSpec(executable='/bin/sleep', arguments=['1']))
50+
ex = _get_executor_instance(execparams, job)
51+
ex.submit(job)
52+
job.wait(target_states=[JobState.ACTIVE, JobState.COMPLETED])
53+
native_id = job.native_id
54+
55+
assert native_id is not None
56+
job2 = Job()
57+
ex2 = _get_executor_instance(execparams)
58+
ex2.attach(job2, native_id)
59+
status = job2.wait(timeout=_get_timeout(execparams))
60+
assert_completed(job2, status)
61+
62+
4863
def test_cancel(execparams: ExecutorTestParams) -> None:
4964
job = Job(JobSpec(executable='/bin/sleep', arguments=['60']))
5065
ex = _get_executor_instance(execparams, job)

0 commit comments

Comments
 (0)