24 lines
1.2 KiB
Python
24 lines
1.2 KiB
Python
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'coordinator'))
|
|
from robot_bt_coordinator.service import Coordinator
|
|
from robot_bt_coordinator.backends import ManualBackend
|
|
from robot_bt_coordinator.replay import replay_events
|
|
|
|
class ReplayTest(unittest.TestCase):
|
|
def test_real_canceled_task_replays_without_transport(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
c=Coordinator(str(Path(tmp)/'db'),ManualBackend(),{'robot_01'})
|
|
try:
|
|
tid=c.submit(dict(client_request_id='replay',robot_id='robot_01',instruction='取水'))['task_id']
|
|
c.control(tid,'cancel');events=c.events(tid)
|
|
out=replay_events(events)
|
|
self.assertEqual(out['status'],'CANCELED');self.assertFalse(out['connects_to_robot'])
|
|
finally:c.close()
|
|
def test_missing_status_event_detected(self):
|
|
with self.assertRaises(ValueError):replay_events([dict(event_id=10,kind='state',status_version=3,status='EXECUTING')])
|
|
def test_success_without_commit_is_not_replayed_as_success(self):
|
|
with self.assertRaises(ValueError):replay_events([dict(event_id=1,kind='state',status_version=1,status='SUCCEEDED')])
|