-
Notifications
You must be signed in to change notification settings - Fork 202
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
Deepskyhunter
wants to merge
35
commits into
m-labs:master
Choose a base branch
from
Deepskyhunter:iss1888-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
9191d74
Add alternative to test case
6f89438
Revert "Add alternative to test case"
0c1da82
Modify expect and _get_basic_steps and create last_state_RID
ea53aba
Modify notify to suit the test case and change order of a function
52c6bb3
Re-order the parameters in _get_basic_steps
a9f1217
Remove space in args in _get_basic_steps
a09236d
Rename last_state to expect_next_state and Add comments
04a3c73
Flake8 correction
6f00de0
Keep track of each RID and its change from pending to preparing
0488c94
test_scheduler: Skip next check after reached done state
e9b1383
test_scheduler: Add SchedulerMonitor
1b06ab3
test_scheduler: Rename SchedulerMonitor.schedulers to experiments
a148b3e
SchedulerMonitor: Add records with time element
0b91f53
Add missing colon
99ffd59
SchedulerMonitor: Add status_record and related assert
c5f97a0
Rename scheduler_mon and records
b52d9fa
SchedulerMonitor: Add get_status_order
6c42c46
SchedulerMonitor: Add end_condition args
6c06512
Remove () after SchedulerMonitor
f8f0d34
SchedulerMonitor: Structure exp_flow
8c2501f
SchedulerMonitor: Add wait_until() and flags
bdad183
test_pending_priority: Replace done with monitor.wait_until
d7630a9
test_scheduler: Use monitor.wait_until and assert with basic_flow
f9bce0c
test_scheduler: remove _get_basic_steps
566909d
test_flush: test with different priority case
4357546
test_pause: Add comments and assert before request termination
c06a090
test_pending: Use asyncio.wait and update monitor
cd0465b
Scheduler: Remove status_records, get_in_time and get_out_time
ada6d27
scheduler: Remove end_condition and bool finished
0efa3db
scheduler: Replace notify by monitor.record
ee7d6b0
SchedulerMonitor: Apply flow check in record
e5bcbdf
Scheduler: Rename var for better understanding
36a36c3
Scheduler_monitor: Put flow_map into class attribute
a6df1ed
test_scheduler: Put duplicated code to setUp() and tearDown()
81a6559
test_scheduler: Create and apply AssertScheduler
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,10 @@ | |
|
||
from artiq.experiment import * | ||
from artiq.master.scheduler import Scheduler | ||
from sipyco.sync_struct import process_mod | ||
|
||
basic_flow = ["pending", "preparing", "prepare_done", "running", | ||
"run_done", "analyzing", "deleting"] | ||
|
||
class EmptyExperiment(EnvExperiment): | ||
def build(self): | ||
|
@@ -50,11 +53,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", | ||
|
@@ -82,6 +85,59 @@ def get(self): | |
self._next_rid += 1 | ||
return rid | ||
|
||
class SchedulerMonitor(): | ||
def __init__(self, end_condition = "deleting"): | ||
self.experiments = {} | ||
self.last_status = {} | ||
self.exp_flow = {} | ||
self.status_records = { | ||
"pending": [], | ||
"preparing": [], | ||
"prepare_done": [], | ||
"running": [], | ||
"run_done": [], | ||
"analyzing": [], | ||
"deleting": [], | ||
"paused": [] | ||
} | ||
self.finished = False | ||
self.end_condition = end_condition | ||
|
||
def record(self): | ||
for key, value in self.experiments.items(): | ||
if key not in self.last_status.keys(): | ||
self.last_status[key] = "" | ||
self.exp_flow[key] = [] | ||
current_status = self.experiments[key]["status"] | ||
if current_status != self.last_status[key]: | ||
self.last_status[key] = current_status | ||
self.exp_flow[key].append(time()) | ||
self.exp_flow[key].append(current_status) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. Structure it. |
||
self.status_records[current_status].append(key) | ||
|
||
if current_status == self.end_condition: | ||
self.finished = True | ||
return | ||
|
||
def get_in_time(self, rid, status): | ||
return self.exp_flow[rid][self.exp_flow[rid].index(status)-1] | ||
|
||
def get_out_time(self, rid, status): | ||
if self.exp_flow[rid][-1] == status: | ||
return "never" | ||
else: | ||
return self.exp_flow[rid][self.exp_flow[rid].index(status) + 1] | ||
|
||
def get_exp_order(self, status): | ||
return self.status_records[status] | ||
|
||
def get_status_order(self, rid): | ||
result_list = self.exp_flow[rid].copy() | ||
for item in result_list: | ||
if isinstance(item, float): | ||
result_list.remove(item) | ||
return result_list | ||
|
||
|
||
class SchedulerCase(unittest.TestCase): | ||
def setUp(self): | ||
|
@@ -96,6 +152,7 @@ def test_steps(self): | |
expect = _get_basic_steps(1, expid) | ||
done = asyncio.Event() | ||
expect_idx = 0 | ||
|
||
def notify(mod): | ||
nonlocal expect_idx | ||
self.assertEqual(mod, expect[expect_idx]) | ||
|
@@ -144,129 +201,17 @@ 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 | ||
}, | ||
] | ||
monitor = SchedulerMonitor() | ||
|
||
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): | ||
process_mod(monitor.experiments, mod) | ||
monitor.record() | ||
|
||
if monitor.finished: | ||
done.set() | ||
|
||
scheduler.notifier.publish = notify | ||
|
||
scheduler.start() | ||
|
@@ -279,6 +224,15 @@ def notify(mod): | |
scheduler.notifier.publish = None | ||
loop.run_until_complete(scheduler.stop()) | ||
|
||
# Assert | ||
self.assertEqual(monitor.get_exp_order("preparing"), [0, 2]) | ||
self.assertEqual(monitor.get_out_time(1, "pending"), "never", | ||
"RID 1 has left pending") | ||
basic_flow = ["pending", "preparing", "prepare_done", "running", | ||
"run_done", "analyzing", "deleting"] | ||
self.assertEqual(monitor.get_status_order(2), basic_flow, | ||
"RID 2 did not go through all stage") | ||
|
||
def test_pause(self): | ||
loop = self.loop | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove ()