Skip to content

Commit

Permalink
Merge pull request #351 from alexhsamuel/fix/protocol-cleanup
Browse files Browse the repository at this point in the history
restart test
  • Loading branch information
alexhsamuel authored Aug 20, 2024
2 parents 1ae7830 + b41f500 commit f859868
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 3 deletions.
2 changes: 0 additions & 2 deletions python/apsis/lib/asyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import logging

import logging

#-------------------------------------------------------------------------------

def _install():
Expand Down
2 changes: 1 addition & 1 deletion test/int/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def start_serve(self):


def wait_for_serve(self):
self.client.wait_running(1)
self.client.wait_running(2)


def is_running(self):
Expand Down
7 changes: 7 additions & 0 deletions test/int/procstar/jobs/group sleep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
params: {duration, group_id}

program:
type: procstar
group_id: "{{ group_id }}"
argv: ["/usr/bin/sleep", "{{ duration }}"]

56 changes: 56 additions & 0 deletions test/int/procstar/test_restart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from pathlib import Path
import logging
import time

from procstar_instance import ApsisService

JOB_DIR = Path(__file__).parent / "jobs"

#-------------------------------------------------------------------------------

def _start(svc, job_id, args):
"""
Starts a run for `job_id` and `args`, and waits for it to start running.
"""
run_id = svc.client.schedule(job_id, args)["run_id"]
assert svc.wait_run(run_id, wait_states=("starting", ))["state"] == "running"
return run_id


def test_restart_some():
"""
Tests restarting some agents but not others, while processes run.
"""
with (
ApsisService(job_dir=JOB_DIR) as svc,
svc.agent(group_id="group0") as agent0,
svc.agent(group_id="group1"),
svc.agent(group_id="group2") as agent2,
):
svc.client.wait_running(1)
# Start runs in groups 1 and 2.
run_id0 = _start(svc, "group sleep", {"group_id": "group0", "duration": "2"})
run_id1 = _start(svc, "group sleep", {"group_id": "group1", "duration": "2"})

# Restart agent 2.
agent2.restart()

# The runs should be unaffected.
assert svc.client.get_run(run_id0)["state"] == "running"
assert svc.client.get_run(run_id1)["state"] == "running"

# Restart agent 0. Run 0 should error.
agent0.restart()
time.sleep(0.1)
assert svc.client.get_run(run_id0)["state"] == "failure" # SIGTERM
assert svc.client.get_run(run_id1)["state"] == "running"

assert svc.wait_run(run_id1)["state"] == "success"


if __name__ == "__main__":
from apsis.lib import logging
logging.configure(level="DEBUG")
logging.set_log_levels()
test_restart_some()

12 changes: 12 additions & 0 deletions test/int/procstar_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def close(self):
self.proc = None


def restart(self, *, signum=signal.SIGTERM, keep_conn_id=False):
logging.info("killing Procstar agent")
self.proc.send_signal(signum)
self.proc.wait()
self.proc = None

if not keep_conn_id:
self.conn_id = str(uuid.uuid4())

self.start()


def __enter__(self):
self.start()
return self
Expand Down

0 comments on commit f859868

Please sign in to comment.