Skip to content

Commit c13b428

Browse files
committed
test_scheduler: remove the exact ordering assertion
Currently the exact ordering is compared in the `pending_priorities` test which is not necessary and is non-deterministic. This patch only asserts the middle priority experiment is ran before the high priority experiment scheduled in the future. Signed-off-by: Kanyang Ying <[email protected]>
1 parent 4a88693 commit c13b428

File tree

1 file changed

+9
-120
lines changed

1 file changed

+9
-120
lines changed

artiq/test/test_scheduler.py

+9-120
Original file line numberDiff line numberDiff line change
@@ -141,132 +141,21 @@ def test_pending_priority(self):
141141
high_priority = 3
142142
middle_priority = 2
143143
low_priority = 1
144+
# The time used by "high_priority" experiment is far enough into the future, beyond reasonable test timeout.
145+
# Thus if the "middle_priority" experiment is scheduled after "high_priority" experiment, then it would be completed, thus failing the test.
144146
late = time() + 100000
145147
early = time() + 1
146148

147-
expect = [
148-
{
149-
"path": [],
150-
"action": "setitem",
151-
"value": {
152-
"repo_msg": None,
153-
"priority": low_priority,
154-
"pipeline": "main",
155-
"due_date": None,
156-
"status": "pending",
157-
"expid": expid_bg,
158-
"flush": False
159-
},
160-
"key": 0
161-
},
162-
{
163-
"path": [],
164-
"action": "setitem",
165-
"value": {
166-
"repo_msg": None,
167-
"priority": high_priority,
168-
"pipeline": "main",
169-
"due_date": late,
170-
"status": "pending",
171-
"expid": expid_empty,
172-
"flush": False
173-
},
174-
"key": 1
175-
},
176-
{
177-
"path": [],
178-
"action": "setitem",
179-
"value": {
180-
"repo_msg": None,
181-
"priority": middle_priority,
182-
"pipeline": "main",
183-
"due_date": early,
184-
"status": "pending",
185-
"expid": expid_empty,
186-
"flush": False
187-
},
188-
"key": 2
189-
},
190-
{
191-
"path": [0],
192-
"action": "setitem",
193-
"value": "preparing",
194-
"key": "status"
195-
},
196-
{
197-
"path": [0],
198-
"action": "setitem",
199-
"value": "prepare_done",
200-
"key": "status"
201-
},
202-
{
203-
"path": [0],
204-
"action": "setitem",
205-
"value": "running",
206-
"key": "status"
207-
},
208-
{
209-
"path": [2],
210-
"action": "setitem",
211-
"value": "preparing",
212-
"key": "status"
213-
},
214-
{
215-
"path": [2],
216-
"action": "setitem",
217-
"value": "prepare_done",
218-
"key": "status"
219-
},
220-
{
221-
"path": [0],
222-
"action": "setitem",
223-
"value": "paused",
224-
"key": "status"
225-
},
226-
{
227-
"path": [2],
228-
"action": "setitem",
229-
"value": "running",
230-
"key": "status"
231-
},
232-
{
149+
middle_priority_done = asyncio.Event()
150+
def notify(mod):
151+
# Watch for the "middle_priority" experiment's completion
152+
if mod == {
233153
"path": [2],
234154
"action": "setitem",
235155
"value": "run_done",
236156
"key": "status"
237-
},
238-
{
239-
"path": [0],
240-
"action": "setitem",
241-
"value": "running",
242-
"key": "status"
243-
},
244-
{
245-
"path": [2],
246-
"action": "setitem",
247-
"value": "analyzing",
248-
"key": "status"
249-
},
250-
{
251-
"path": [2],
252-
"action": "setitem",
253-
"value": "deleting",
254-
"key": "status"
255-
},
256-
{
257-
"path": [],
258-
"action": "delitem",
259-
"key": 2
260-
},
261-
]
262-
done = asyncio.Event()
263-
expect_idx = 0
264-
def notify(mod):
265-
nonlocal expect_idx
266-
self.assertEqual(mod, expect[expect_idx])
267-
expect_idx += 1
268-
if expect_idx >= len(expect):
269-
done.set()
157+
}:
158+
middle_priority_done.set()
270159
scheduler.notifier.publish = notify
271160

272161
scheduler.start(loop=loop)
@@ -275,7 +164,7 @@ def notify(mod):
275164
scheduler.submit("main", expid_empty, high_priority, late)
276165
scheduler.submit("main", expid_empty, middle_priority, early)
277166

278-
loop.run_until_complete(done.wait())
167+
loop.run_until_complete(middle_priority_done.wait())
279168
scheduler.notifier.publish = None
280169
loop.run_until_complete(scheduler.stop())
281170

0 commit comments

Comments
 (0)