-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add state pickler * Basic job state recovery tests. * More reliable state tests. * Fix waiting test. * Add crashed-pruning test * Add a 100 ms delay and check false * This is getting silly.
- Loading branch information
1 parent
32f2c33
commit c5796a8
Showing
9 changed files
with
151 additions
and
9 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pickle | ||
import logging | ||
from pathlib import Path | ||
from tomato.models import Daemon | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def store(daemon: Daemon): | ||
outfile = Path(daemon.settings["datadir"]) / f"tomato_state_{daemon.port}.pkl" | ||
logger.debug(f"storing daemon state to {outfile}") | ||
with outfile.open("wb") as out: | ||
pickle.dump(daemon, out) | ||
|
||
|
||
def load(daemon: Daemon): | ||
infile = Path(daemon.settings["datadir"]) / f"tomato_state_{daemon.port}.pkl" | ||
if infile.exists() is False: | ||
logger.debug(f"daemon state file {infile} does not exist") | ||
return | ||
with infile.open("rb") as inp: | ||
loaded = pickle.load(inp) | ||
daemon.jobs = loaded.jobs | ||
daemon.pips = loaded.pips | ||
daemon.devs = loaded.devs | ||
daemon.nextjob = loaded.nextjob |
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import os | ||
from pathlib import Path | ||
import zmq | ||
import time | ||
import psutil | ||
|
||
from tomato import ketchup, tomato | ||
from .utils import wait_until_tomato_running, wait_until_ketchup_status | ||
|
||
PORT = 12345 | ||
CTXT = zmq.Context() | ||
WAIT = 5000 | ||
|
||
kwargs = dict(port=PORT, timeout=1000, context=CTXT) | ||
|
||
|
||
def test_recover_queued_jobs(datadir, start_tomato_daemon, stop_tomato_daemon): | ||
assert wait_until_tomato_running(port=PORT, timeout=WAIT) | ||
os.chdir(datadir) | ||
ketchup.submit(payload="dummy_random_5_2.yml", jobname="job-1", **kwargs) | ||
ketchup.submit(payload="dummy_random_5_2.yml", jobname="job-2", **kwargs) | ||
tomato.stop(**kwargs) | ||
assert not wait_until_tomato_running(port=PORT, timeout=100) | ||
assert os.path.exists("tomato_state_12345.pkl") | ||
|
||
tomato.start(**kwargs, appdir=Path(), logdir=Path(), verbosity=0) | ||
assert wait_until_tomato_running(port=PORT, timeout=WAIT) | ||
ret = tomato.status(**kwargs, with_data=True) | ||
print(f"{ret=}") | ||
assert ret.success | ||
assert len(ret.data.jobs) == 2 | ||
assert ret.data.nextjob == 3 | ||
|
||
|
||
def test_recover_running_jobs(datadir, start_tomato_daemon, stop_tomato_daemon): | ||
assert wait_until_tomato_running(port=PORT, timeout=WAIT) | ||
os.chdir(datadir) | ||
ketchup.submit(payload="dummy_random_5_2.yml", jobname="job-1", **kwargs) | ||
tomato.pipeline_load(**kwargs, pipeline="dummy-5", sampleid="dummy_random_5_2") | ||
tomato.pipeline_ready(**kwargs, pipeline="dummy-5") | ||
wait_until_ketchup_status(jobid=1, status="r", port=PORT, timeout=WAIT) | ||
tomato.stop(**kwargs) | ||
assert not wait_until_tomato_running(port=PORT, timeout=100) | ||
assert os.path.exists("tomato_state_12345.pkl") | ||
|
||
tomato.start(**kwargs, appdir=Path(), logdir=Path(), verbosity=0) | ||
assert wait_until_tomato_running(port=PORT, timeout=WAIT) | ||
ret = tomato.status(**kwargs, with_data=True) | ||
print(f"{ret=}") | ||
assert ret.success | ||
assert len(ret.data.jobs) == 1 | ||
assert ret.data.nextjob == 2 | ||
assert ret.data.jobs[1].status == "r" | ||
|
||
|
||
def test_recover_waiting_jobs(datadir, start_tomato_daemon, stop_tomato_daemon): | ||
assert wait_until_tomato_running(port=PORT, timeout=WAIT) | ||
os.chdir(datadir) | ||
ketchup.submit(payload="dummy_random_5_2.yml", jobname="job-1", **kwargs) | ||
tomato.pipeline_load(**kwargs, pipeline="dummy-5", sampleid="dummy_random_5_2") | ||
tomato.pipeline_ready(**kwargs, pipeline="dummy-5") | ||
wait_until_ketchup_status(jobid=1, status="r", port=PORT, timeout=WAIT) | ||
tomato.stop(**kwargs) | ||
assert not wait_until_tomato_running(port=PORT, timeout=100) | ||
assert os.path.exists("tomato_state_12345.pkl") | ||
|
||
time.sleep(10) | ||
|
||
tomato.start(**kwargs, appdir=Path(), logdir=Path(), verbosity=0) | ||
assert wait_until_tomato_running(port=PORT, timeout=WAIT) | ||
ret = tomato.status(**kwargs, with_data=True) | ||
print(f"{ret=}") | ||
assert ret.success | ||
assert len(ret.data.jobs) == 1 | ||
assert ret.data.nextjob == 2 | ||
assert ret.data.jobs[1].status == "c" | ||
|
||
|
||
def test_prune_crashed_jobs(datadir, start_tomato_daemon, stop_tomato_daemon): | ||
assert wait_until_tomato_running(port=PORT, timeout=WAIT) | ||
os.chdir(datadir) | ||
ketchup.submit(payload="dummy_random_30_1.yml", jobname="job-1", **kwargs) | ||
tomato.pipeline_load(**kwargs, pipeline="dummy-5", sampleid="dummy_random_30_1") | ||
tomato.pipeline_ready(**kwargs, pipeline="dummy-5") | ||
wait_until_ketchup_status(jobid=1, status="r", port=PORT, timeout=WAIT) | ||
ret = tomato.status(**kwargs, with_data=True) | ||
print(f"{ret=}") | ||
tomato.stop(**kwargs) | ||
assert not wait_until_tomato_running(port=PORT, timeout=100) | ||
assert os.path.exists("tomato_state_12345.pkl") | ||
|
||
proc = psutil.Process(pid=ret.data.jobs[1].pid) | ||
proc.terminate() | ||
time.sleep(5) | ||
|
||
tomato.start(**kwargs, appdir=Path(), logdir=Path(), verbosity=0) | ||
assert wait_until_tomato_running(port=PORT, timeout=WAIT) | ||
ret = tomato.status(**kwargs, with_data=True) | ||
print(f"{ret=}") | ||
assert ret.success | ||
assert len(ret.data.jobs) == 1 | ||
assert ret.data.nextjob == 2 | ||
assert ret.data.jobs[1].status == "ce" |
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