Skip to content

Commit 6f00de0

Browse files
author
Deepskyhunter
committed
Keep track of each RID and its change from pending to preparing
Use schedule to record changes from mod. Mark down the order of rid which status changes from pending to preparing in pending_to_preparing.
1 parent 04a3c73 commit 6f00de0

File tree

1 file changed

+12
-35
lines changed

1 file changed

+12
-35
lines changed

artiq/test/test_scheduler.py

+12-35
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from artiq.experiment import *
88
from artiq.master.scheduler import Scheduler
9+
from sipyco.sync_struct import process_mod
910

1011

1112
class EmptyExperiment(EnvExperiment):
@@ -144,44 +145,20 @@ def test_pending_priority(self):
144145
late = time() + 100000
145146
early = time() + 1
146147

147-
expectRID0 = _get_basic_steps(0, expid_bg, low_priority)
148-
expectRID1 = _get_basic_steps(1, expid_empty, high_priority,
149-
due_date=late)
150-
expectRID2 = _get_basic_steps(2, expid_empty, middle_priority,
151-
due_date=early)
152-
# RID0 paused because RID2 reach due_date and has higher priority
153-
expectRID0.insert(4,
154-
{"action": "setitem", "key": "status",
155-
"value": "paused", "path": [0]})
156-
# RID0 resume running after RID finish running
157-
expectRID0.insert(5,
158-
{"action": "setitem", "key": "status",
159-
"value": "running", "path": [0]})
160-
161-
expect = [expectRID0, expectRID1, expectRID2]
162-
163-
# RID0 will never finish running
164-
expect_next_state_RID0 = {"action": "setitem", "key": "status",
165-
"value": "run_done", "path": [0]}
166-
# RID1 will never be preparing
167-
expect_next_state_RID1 = {"action": "setitem", "key": "status",
168-
"value": "preparing", "path": [1]}
169-
# RID2 will go through all stages so it doesn't have expect_next_state
170-
171148
done = asyncio.Event()
172149

150+
schedule = {}
151+
pending_to_preparing = []
152+
173153
def notify(mod):
174-
# Identify the rid
175-
# Two possible location of rid, 1) "key" 2) "path"[0]
176-
if type(mod["key"]) is int:
177-
rid = mod["key"]
178-
else:
179-
rid = mod["path"][0]
180-
self.assertEqual(mod, expect[rid].pop(0))
181-
if len(expect[rid]) == 0:
182-
self.assertEqual(rid, 2)
183-
self.assertEqual(expect[0][0], expect_next_state_RID0)
184-
self.assertEqual(expect[1][0], expect_next_state_RID1)
154+
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])
185162
done.set()
186163

187164
scheduler.notifier.publish = notify

0 commit comments

Comments
 (0)