|
6 | 6 |
|
7 | 7 | from artiq.experiment import *
|
8 | 8 | from artiq.master.scheduler import Scheduler
|
| 9 | +from sipyco.sync_struct import process_mod |
9 | 10 |
|
10 | 11 |
|
11 | 12 | class EmptyExperiment(EnvExperiment):
|
@@ -144,44 +145,20 @@ def test_pending_priority(self):
|
144 | 145 | late = time() + 100000
|
145 | 146 | early = time() + 1
|
146 | 147 |
|
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 |
| - |
171 | 148 | done = asyncio.Event()
|
172 | 149 |
|
| 150 | + schedule = {} |
| 151 | + pending_to_preparing = [] |
| 152 | + |
173 | 153 | 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]) |
185 | 162 | done.set()
|
186 | 163 |
|
187 | 164 | scheduler.notifier.publish = notify
|
|
0 commit comments