41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
"""Control-plane races exercise the real execution commit lock, never a provider."""
|
|
from pathlib import Path
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from harness.execution import Execution
|
|
from harness.rollout import settle_execution
|
|
from scripts.test_execution import policy
|
|
|
|
|
|
class ControlTests(unittest.TestCase):
|
|
def setUp(self):
|
|
temp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(temp.cleanup)
|
|
self.execution = Execution(Path(temp.name))
|
|
self.execution.start(policy())
|
|
|
|
def test_cancel_after_completion_has_no_side_effect(self):
|
|
self.execution.finish(0, protocol_complete=True)
|
|
with patch('harness.collection_runtime.broker') as broker:
|
|
result = settle_execution('r', 'j', 0, self.execution, 'late cancel', cancel=True)
|
|
self.assertEqual(result['execution_outcome'], 'COMPLETED')
|
|
broker.assert_not_called()
|
|
self.assertIsNone(self.execution.snapshot()['cancel_requested'])
|
|
|
|
def test_completion_committed_between_snapshot_and_cancel_wins(self):
|
|
commit_cancel = self.execution.cancel
|
|
def race(reason):
|
|
self.execution.finish(0, protocol_complete=True)
|
|
return commit_cancel(reason)
|
|
with patch.object(self.execution, 'cancel', side_effect=race), patch('harness.collection_runtime.broker') as broker:
|
|
result = settle_execution('r', 'j', 0, self.execution, 'late cancel', cancel=True)
|
|
self.assertEqual(result['execution_outcome'], 'COMPLETED')
|
|
broker.assert_not_called()
|
|
self.assertIsNone(self.execution.snapshot()['cancel_requested'])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|