Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ed9503868180
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 048782e26cd9
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on May 29, 2015

  1. Copy the full SHA
    6ff2e1a View commit details
  2. Copy the full SHA
    048782e View commit details
Showing with 53 additions and 5 deletions.
  1. +53 −5 artiq/test/scheduler.py
58 changes: 53 additions & 5 deletions artiq/test/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import asyncio
import sys
from time import sleep
from time import time, sleep

from artiq import *
from artiq.master.scheduler import Scheduler
@@ -27,11 +27,11 @@ def _get_expid(name):
}


def _get_basic_steps(rid, expid):
def _get_basic_steps(rid, expid, priority=0, flush=False):
return [
{"action": "setitem", "key": rid, "value":
{"pipeline": "main", "status": "pending", "priority": 0,
"expid": expid, "due_date": None, "flush": False},
{"pipeline": "main", "status": "pending", "priority": priority,
"expid": expid, "due_date": None, "flush": flush},
"path": []},
{"action": "setitem", "key": "status", "value": "preparing",
"path": [rid]},
@@ -59,7 +59,7 @@ def test_steps(self):
scheduler = Scheduler(0, _handlers)
expid = _get_expid("EmptyExperiment")

expect = _get_basic_steps(0, expid)
expect = _get_basic_steps(1, expid)
done = asyncio.Event()
expect_idx = 0
def notify(notifier, mod):
@@ -72,8 +72,22 @@ def notify(notifier, mod):

loop = asyncio.get_event_loop()
scheduler.start()

# Verify that a timed experiment far in the future does not
# get run, even if it has high priority.
late = time() + 100000
expect.insert(0,
{"action": "setitem", "key": 0, "value":
{"pipeline": "main", "status": "pending", "priority": 99,
"expid": expid, "due_date": late, "flush": False},
"path": []})
scheduler.submit("main", expid, 99, late, False)

# This one (RID 1) gets run instead.
scheduler.submit("main", expid, 0, None, False)

loop.run_until_complete(done.wait())
scheduler.notifier.publish = None
loop.run_until_complete(scheduler.stop())

def test_pause(self):
@@ -106,3 +120,37 @@ def notify(notifier, mod):
scheduler.submit("main", expid, 0, None, False)
loop.run_until_complete(done.wait())
loop.run_until_complete(scheduler.stop())

def test_flush(self):
scheduler = Scheduler(0, _handlers)
expid = _get_expid("EmptyExperiment")

expect = _get_basic_steps(1, expid, 1, True)
expect.insert(1, {"key": "status",
"path": [1],
"value": "flushing",
"action": "setitem"})
first_preparing = asyncio.Event()
done = asyncio.Event()
expect_idx = 0
def notify(notifier, mod):
nonlocal expect_idx
if mod == {"path": [0],
"value": "preparing",
"key": "status",
"action": "setitem"}:
first_preparing.set()
if mod["path"] == [1] or (mod["path"] == [] and mod["key"] == 1):
self.assertEqual(mod, expect[expect_idx])
expect_idx += 1
if expect_idx >= len(expect):
done.set()
scheduler.notifier.publish = notify

loop = asyncio.get_event_loop()
scheduler.start()
scheduler.submit("main", expid, 0, None, False)
loop.run_until_complete(first_preparing.wait())
scheduler.submit("main", expid, 1, None, True)
loop.run_until_complete(done.wait())
loop.run_until_complete(scheduler.stop())