Skip to content

Commit 0488c94

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 0488c94

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

artiq/test/test_scheduler.py

+36-10
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,46 @@ def test_pending_priority(self):
145145
late = time() + 100000
146146
early = time() + 1
147147

148-
done = asyncio.Event()
149-
150148
schedule = {}
151-
pending_to_preparing = []
149+
150+
expect = [
151+
{0: "pending"},
152+
{0: "pending", 1: "pending"},
153+
{0: "pending", 1: "pending", 2: "pending"},
154+
{0: "preparing", 1: "pending", 2: "pending"},
155+
{0: "prepare_done", 1: "pending", 2: "pending"},
156+
{0: "running", 1: "pending", 2: "preparing"},
157+
{0: "running", 1: "pending", 2: "prepare_done"},
158+
{0: "paused", 1: "pending", 2: "running"},
159+
{0: "paused", 1: "pending", 2: "run_done"},
160+
{0: "running", 1: "pending", 2: "analyzing"},
161+
{0: "running", 1: "pending", 2: "deleting"},
162+
]
163+
164+
done = asyncio.Event()
165+
expect_idx = 0
166+
skip_next = False
152167

153168
def notify(mod):
169+
nonlocal expect_idx, skip_next
154170
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])
171+
172+
# gather status of each RID
173+
current_status = {}
174+
for rid, info in schedule.items():
175+
current_status[rid] = info["status"]
176+
177+
# skip once after prepare_done or run_done
178+
if skip_next:
179+
skip_next = False
180+
else:
181+
self.assertEqual(current_status, expect[expect_idx])
182+
expect_idx += 1
183+
if "prepare_done" in current_status.values() or\
184+
"run_done" in current_status.values():
185+
skip_next = True
186+
187+
if expect_idx >= len(expect):
162188
done.set()
163189

164190
scheduler.notifier.publish = notify

0 commit comments

Comments
 (0)