def test_run_worker(engine): mon = Monitor(engine, maxruns=1) wid = mon.new_worker() t = api.schedule(engine, 'print_sleep_and_go_away', 0) worker = Worker(engine.url, wid, os.getppid(), maxruns=1) worker.run() assert t.state == 'done'
def test_basic_worker_operations(engine): mon = Monitor(engine) wid = mon.new_worker() worker = Worker(engine.url, wid) with worker.running_status(): assert engine.execute( 'select count(id) from rework.worker where running = true').scalar( ) == 1 assert engine.execute( 'select count(id) from rework.worker where running = true').scalar( ) == 0
def test_basic_task_operations(engine): api.schedule(engine, 'print_sleep_and_go_away', 21, metadata={'user': '******'}) known = [(name, Path(path).name) for name, path in engine.execute( 'select name, path from rework.operation order by name').fetchall()] assert [ ('allocate_and_leak_mbytes', 'tasks.py'), ('capture_logs', 'tasks.py'), ('flush_captured_stdout', 'tasks.py'), ('infinite_loop', 'tasks.py'), ('infinite_loop_long_timeout', 'tasks.py'), ('infinite_loop_timeout', 'tasks.py'), ('log_swarm', 'tasks.py'), ('normal_exception', 'tasks.py'), ('print_sleep_and_go_away', 'tasks.py'), ('raw_input', 'tasks.py'), ('run_in_non_default_domain', 'tasks.py'), ('stderr_swarm', 'tasks.py'), ('unstopable_death', 'tasks.py'), ] == known mon = Monitor(engine) wid = mon.new_worker() t = Task.fromqueue(engine, wid) t.run() assert t.output == 42 assert t.metadata == {'user': '******'} cdate = t._propvalue('queued') now = datetime.now() assert now.year == cdate.year assert now.month == cdate.month t2 = Task.byid(engine, t.tid) assert (t2.tid, t2.operation) == (t.tid, t.operation) t3 = Task.byid(engine, 42000) assert t3 is None with pytest.raises(Exception) as err: api.schedule(engine, 'no_such_task') assert err.value.args[0] == 'No operation was found for these parameters'