Skip to content

Commit

Permalink
test_scheduler: Skip next check after reached done state
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Deepskyhunter committed Jul 12, 2022
1 parent 6f00de0 commit b4bc477
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions artiq/test/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,41 @@ def test_pending_priority(self):
done = asyncio.Event()

schedule = {}
pending_to_preparing = []

expect = [
{0: "pending"},
{0: "pending", 1: "pending"},
{0: "pending", 1: "pending", 2: "pending"},
{0: "preparing", 1: "pending", 2: "pending"},
{0: "running", 1: "pending", 2: "preparing"},
{0: "paused", 1: "pending", 2: "running"},
{0: "running", 1: "pending", 2: "analyzing"},
{0: "running", 1: "pending", 2: "deleting"},
]
expect_idx = 0
skip_next = False

def notify(mod):
nonlocal expect_idx, skip_next
process_mod(schedule, mod)
for key in schedule:
if schedule[key]["status"] == "preparing":
if key not in pending_to_preparing:
pending_to_preparing.append(key)
# Expect only two rid would go to preparing
if len(pending_to_preparing) == 2:
self.assertEqual(pending_to_preparing, [0, 2])

# gather status of each RID
current_status = {}
for rid, info in schedule.items():
current_status[rid] = info["status"]

# ignore intermediate state
if skip_next:
skip_next = False
else:
if "prepare_done" not in current_status.values() and\
"run_done" not in current_status.values():
self.assertEqual(current_status, expect[expect_idx])
expect_idx += 1
else:
skip_next = True

if expect_idx >= len(expect):
done.set()

scheduler.notifier.publish = notify
Expand Down

0 comments on commit b4bc477

Please sign in to comment.