Skip to content

Commit 944771d

Browse files
committed
tests: Adjust tests for query_job_state
- Semantics of the status changes slightly, adjust to the new form - Add split the starting test: - job status query fails when it is first submitted - job status query fails after it has started
1 parent c81298d commit 944771d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

batchspawner/tests/test_spawners.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import re
44
from unittest import mock
5-
from .. import BatchSpawnerRegexStates
5+
from .. import BatchSpawnerRegexStates, JobStatus
66
from traitlets import Unicode
77
import time
88
import pytest
@@ -135,15 +135,32 @@ def test_submit_failure(db, io_loop):
135135
assert spawner.job_id == ''
136136
assert spawner.job_status == ''
137137

138-
def test_pending_fails(db, io_loop):
138+
def test_submit_pending_fails(db, io_loop):
139+
"""Submission works, but the batch query command immediately fails"""
139140
spawner = new_spawner(db=db)
140141
assert spawner.get_state() == {}
141142
spawner.batch_query_cmd = 'echo xyz'
142143
with pytest.raises(RuntimeError) as e_info:
143144
io_loop.run_sync(spawner.start, timeout=30)
145+
status = io_loop.run_sync(spawner.query_job_status, timeout=30)
146+
assert status == JobStatus.NOTFOUND
144147
assert spawner.job_id == ''
145148
assert spawner.job_status == ''
146149

150+
def test_poll_fails(db, io_loop):
151+
"""Submission works, but a later .poll() fails"""
152+
spawner = new_spawner(db=db)
153+
assert spawner.get_state() == {}
154+
# The start is successful:
155+
io_loop.run_sync(spawner.start, timeout=30)
156+
spawner.batch_query_cmd = 'echo xyz'
157+
# Now, the poll fails:
158+
io_loop.run_sync(spawner.poll, timeout=30)
159+
# .poll() will run self.clear_state() if it's not found:
160+
assert spawner.job_id == ''
161+
assert spawner.job_status == ''
162+
163+
147164
def test_templates(db, io_loop):
148165
"""Test templates in the run_command commands"""
149166
spawner = new_spawner(db=db)

0 commit comments

Comments
 (0)