Fix native health polling and isolate file operation traffic
This commit is contained in:
@@ -118,6 +118,44 @@ class UpdateIntegrationTests(unittest.TestCase):
|
||||
self.agent.read_loop()
|
||||
dispatch.assert_not_called()
|
||||
|
||||
def test_health_lane_runs_while_file_receipt_for_same_instance_is_slow(self):
|
||||
receipt_waiting, release_receipt, health_done = threading.Event(), threading.Event(), threading.Event()
|
||||
file_op = {"id": "file-one", "kind": "files.read", "instanceId": "same", "payload": {}}
|
||||
health_op = {"id": "health-one", "kind": "instance.inspect", "instanceId": "same", "payload": {}}
|
||||
errors = []
|
||||
def request(method, path, body=None):
|
||||
if method == "GET":
|
||||
return {"operations": [health_op if "lane=health" in path else file_op]}
|
||||
if path.endswith("file-one") and body["state"] == "completed":
|
||||
receipt_waiting.set()
|
||||
release_receipt.wait(3)
|
||||
return {}
|
||||
def dispatch(operation):
|
||||
if operation["id"] == "health-one":
|
||||
health_done.set()
|
||||
self.agent.stopping.set()
|
||||
return {"ok": True}
|
||||
def run(lane):
|
||||
try: self.agent.read_loop(lane)
|
||||
except Exception as error: errors.append(error)
|
||||
self.agent.request, self.agent.dispatch = request, dispatch
|
||||
files = threading.Thread(target=run, args=("read",))
|
||||
health = threading.Thread(target=run, args=("health",))
|
||||
files.start()
|
||||
try:
|
||||
self.assertTrue(receipt_waiting.wait(2))
|
||||
health.start()
|
||||
self.assertTrue(health_done.wait(2), "Health waited for a file receipt")
|
||||
finally:
|
||||
self.agent.stopping.set()
|
||||
release_receipt.set()
|
||||
files.join(3)
|
||||
if health.ident is not None: health.join(3)
|
||||
self.assertFalse(files.is_alive())
|
||||
self.assertFalse(health.is_alive())
|
||||
self.assertEqual(errors, [])
|
||||
self.assertEqual(self.agent.journal.get("health-one")["state"], "completed")
|
||||
|
||||
def test_instance_mutations_and_global_mutations_exclude_observations(self):
|
||||
operation = {"instanceId": "one"}
|
||||
entered = threading.Event()
|
||||
|
||||
Reference in New Issue
Block a user