Files
orisys_arm/station/test/test_processes.py
T
2026-10-16 17:27:30 +08:00

22 lines
927 B
Python

import sys
import tempfile
import threading
import time
from unittest import TestCase
from station.processes import ProcessSupervisor
from station.tasks import Cancelled
class ProcessesTest(TestCase):
def test_owned_process_cancel_and_exit(self):
with tempfile.TemporaryDirectory() as directory:
processes=ProcessSupervisor(directory)
try:
result=processes.run('echo',[sys.executable,'-c','print("completed")'],threading.Event())
self.assertTrue(result['ok']);self.assertIn('completed',result['detail'])
event=threading.Event();timer=threading.Timer(.2,event.set);timer.start()
with self.assertRaises(Cancelled):
processes.run('long',[sys.executable,'-c','import time;time.sleep(30)'],event)
self.assertFalse(processes.snapshot()['long']['running'])
finally: processes.close()