Skip to content

Commit b4bc477

Browse files
author
Deepskyhunter
committed
test_scheduler: Skip next check after reached done state
Two RID would change status at the same time when one of them entering done state (prepare_done and run_done). So once any of them enter that state, checking in next notify would be skipped.
1 parent 6f00de0 commit b4bc477

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

artiq/test/test_scheduler.py

+32-8
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,41 @@ def test_pending_priority(self):
148148
done = asyncio.Event()
149149

150150
schedule = {}
151-
pending_to_preparing = []
151+
152+
expect = [
153+
{0: "pending"},
154+
{0: "pending", 1: "pending"},
155+
{0: "pending", 1: "pending", 2: "pending"},
156+
{0: "preparing", 1: "pending", 2: "pending"},
157+
{0: "running", 1: "pending", 2: "preparing"},
158+
{0: "paused", 1: "pending", 2: "running"},
159+
{0: "running", 1: "pending", 2: "analyzing"},
160+
{0: "running", 1: "pending", 2: "deleting"},
161+
]
162+
expect_idx = 0
163+
skip_next = False
152164

153165
def notify(mod):
166+
nonlocal expect_idx, skip_next
154167
process_mod(schedule, mod)
155-
for key in schedule:
156-
if schedule[key]["status"] == "preparing":
157-
if key not in pending_to_preparing:
158-
pending_to_preparing.append(key)
159-
# Expect only two rid would go to preparing
160-
if len(pending_to_preparing) == 2:
161-
self.assertEqual(pending_to_preparing, [0, 2])
168+
169+
# gather status of each RID
170+
current_status = {}
171+
for rid, info in schedule.items():
172+
current_status[rid] = info["status"]
173+
174+
# ignore intermediate state
175+
if skip_next:
176+
skip_next = False
177+
else:
178+
if "prepare_done" not in current_status.values() and\
179+
"run_done" not in current_status.values():
180+
self.assertEqual(current_status, expect[expect_idx])
181+
expect_idx += 1
182+
else:
183+
skip_next = True
184+
185+
if expect_idx >= len(expect):
162186
done.set()
163187

164188
scheduler.notifier.publish = notify

0 commit comments

Comments
 (0)