Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Scheduler by the state progress of each RID #1920

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Changes from 6 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9191d74
Add alternative to test case
Jun 21, 2022
6f89438
Revert "Add alternative to test case"
Jun 22, 2022
0c1da82
Modify expect and _get_basic_steps and create last_state_RID
Jun 22, 2022
ea53aba
Modify notify to suit the test case and change order of a function
Jun 22, 2022
52c6bb3
Re-order the parameters in _get_basic_steps
Jun 22, 2022
a9f1217
Remove space in args in _get_basic_steps
Jun 22, 2022
a09236d
Rename last_state to expect_next_state and Add comments
Jun 23, 2022
04a3c73
Flake8 correction
Jun 23, 2022
6f00de0
Keep track of each RID and its change from pending to preparing
Jun 23, 2022
0488c94
test_scheduler: Skip next check after reached done state
Jul 12, 2022
e9b1383
test_scheduler: Add SchedulerMonitor
Jul 13, 2022
1b06ab3
test_scheduler: Rename SchedulerMonitor.schedulers to experiments
Jul 13, 2022
a148b3e
SchedulerMonitor: Add records with time element
Jul 14, 2022
0b91f53
Add missing colon
Jul 14, 2022
99ffd59
SchedulerMonitor: Add status_record and related assert
Jul 14, 2022
c5f97a0
Rename scheduler_mon and records
Jul 14, 2022
b52d9fa
SchedulerMonitor: Add get_status_order
Jul 14, 2022
6c42c46
SchedulerMonitor: Add end_condition args
Jul 14, 2022
6c06512
Remove () after SchedulerMonitor
Jul 15, 2022
f8f0d34
SchedulerMonitor: Structure exp_flow
Jul 15, 2022
8c2501f
SchedulerMonitor: Add wait_until() and flags
Jul 18, 2022
bdad183
test_pending_priority: Replace done with monitor.wait_until
Jul 18, 2022
d7630a9
test_scheduler: Use monitor.wait_until and assert with basic_flow
Jul 18, 2022
f9bce0c
test_scheduler: remove _get_basic_steps
Jul 20, 2022
566909d
test_flush: test with different priority case
Jul 20, 2022
4357546
test_pause: Add comments and assert before request termination
Jul 21, 2022
c06a090
test_pending: Use asyncio.wait and update monitor
Jul 21, 2022
cd0465b
Scheduler: Remove status_records, get_in_time and get_out_time
Jul 29, 2022
ada6d27
scheduler: Remove end_condition and bool finished
Jul 29, 2022
0efa3db
scheduler: Replace notify by monitor.record
Jul 29, 2022
ee7d6b0
SchedulerMonitor: Apply flow check in record
Jul 29, 2022
e5bcbdf
Scheduler: Rename var for better understanding
Jul 29, 2022
36a36c3
Scheduler_monitor: Put flow_map into class attribute
Aug 1, 2022
a6df1ed
test_scheduler: Put duplicated code to setUp() and tearDown()
Aug 5, 2022
81a6559
test_scheduler: Create and apply AssertScheduler
Aug 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 32 additions & 122 deletions artiq/test/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ def _get_expid(name):
}


def _get_basic_steps(rid, expid, priority=0, flush=False):
def _get_basic_steps(rid, expid, priority=0, flush=False, due_date=None):
return [
{"action": "setitem", "key": rid, "value":
{"pipeline": "main", "status": "pending", "priority": priority,
"expid": expid, "due_date": None, "flush": flush,
"expid": expid, "due_date": due_date, "flush": flush,
"repo_msg": None},
"path": []},
{"action": "setitem", "key": "status", "value": "preparing",
Expand Down Expand Up @@ -144,129 +144,39 @@ def test_pending_priority(self):
late = time() + 100000
early = time() + 1

expect = [
{
"path": [],
"action": "setitem",
"value": {
"repo_msg": None,
"priority": low_priority,
"pipeline": "main",
"due_date": None,
"status": "pending",
"expid": expid_bg,
"flush": False
},
"key": 0
},
{
"path": [],
"action": "setitem",
"value": {
"repo_msg": None,
"priority": high_priority,
"pipeline": "main",
"due_date": late,
"status": "pending",
"expid": expid_empty,
"flush": False
},
"key": 1
},
{
"path": [],
"action": "setitem",
"value": {
"repo_msg": None,
"priority": middle_priority,
"pipeline": "main",
"due_date": early,
"status": "pending",
"expid": expid_empty,
"flush": False
},
"key": 2
},
{
"path": [0],
"action": "setitem",
"value": "preparing",
"key": "status"
},
{
"path": [0],
"action": "setitem",
"value": "prepare_done",
"key": "status"
},
{
"path": [0],
"action": "setitem",
"value": "running",
"key": "status"
},
{
"path": [2],
"action": "setitem",
"value": "preparing",
"key": "status"
},
{
"path": [2],
"action": "setitem",
"value": "prepare_done",
"key": "status"
},
{
"path": [0],
"action": "setitem",
"value": "paused",
"key": "status"
},
{
"path": [2],
"action": "setitem",
"value": "running",
"key": "status"
},
{
"path": [2],
"action": "setitem",
"value": "run_done",
"key": "status"
},
{
"path": [0],
"action": "setitem",
"value": "running",
"key": "status"
},
{
"path": [2],
"action": "setitem",
"value": "analyzing",
"key": "status"
},
{
"path": [2],
"action": "setitem",
"value": "deleting",
"key": "status"
},
{
"path": [],
"action": "delitem",
"key": 2
},
]
expectRID0 = _get_basic_steps(0, expid_bg, low_priority)
expectRID1 = _get_basic_steps(1, expid_empty, high_priority,
due_date=late)
expectRID2 = _get_basic_steps(2, expid_empty, middle_priority,
due_date=early)
expectRID0.insert(4,
{"action": "setitem", "key": "status", "value": "paused",
"path": [0]})
expectRID0.insert(5,
{"action": "setitem", "key": "status", "value": "running",
"path": [0]})

expect = [expectRID0, expectRID1, expectRID2]

last_state_RID0 = {"action": "setitem", "key": "status",
"value": "run_done", "path": [0]}
last_state_RID1 = {"action": "setitem", "key": "status",
"value": "preparing", "path": [1]}

done = asyncio.Event()
expect_idx = 0

def notify(mod):
nonlocal expect_idx
self.assertEqual(mod, expect[expect_idx])
expect_idx += 1
if expect_idx >= len(expect):
if type(mod["key"]) is int:
rid = mod["key"]
else:
rid = mod["path"][0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is that doing? There should at least be an explanatory comment in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for finding the RID of the mod

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had guessed as much, but why is it done that way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to look at mod["action"]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I have separated the expect case into 3 for each RID, then monitor which state does it go through.
This way can know what they are up to without a conflict of slight time delay.

self.assertEqual(mod, expect[rid].pop(0))
if len(expect[rid]) == 0:
self.assertEqual(rid, 2)
self.assertEqual(expect[0][0], last_state_RID0)
self.assertEqual(expect[1][0], last_state_RID1)
done.set()

scheduler.notifier.publish = notify

scheduler.start()
Expand Down