Compact a waiting worker's session shortly before its prompt cache expires
CI / tests (pull_request) Failing after 3m16s
CI / tests (pull_request) Failing after 3m16s
This commit is contained in:
@@ -6,13 +6,14 @@ import pathlib
|
||||
import signal
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
import unittest.mock
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from loop_effects.effects import run_python, say, system_effects
|
||||
from loop_effects.effects import run_python, say, start_timer, system_effects
|
||||
|
||||
NOW = 1790000000
|
||||
# How a line said at NOW opens, with clocked's local_time.
|
||||
@@ -134,3 +135,27 @@ class PythonEffect(unittest.TestCase):
|
||||
done = run_python(["-c", "pass"], gone, 60)
|
||||
self.assertEqual(done.returncode, 1)
|
||||
self.assertIn(gone, done.stderr)
|
||||
|
||||
|
||||
class Timer(unittest.TestCase):
|
||||
def test_runs_the_action_beside_the_caller_once_the_delay_has_passed(self):
|
||||
ran = threading.Event()
|
||||
start_timer(0.05, ran.set)
|
||||
self.assertTrue(ran.wait(10))
|
||||
|
||||
def test_a_timer_stopped_before_its_delay_has_passed_never_runs_the_action(self):
|
||||
ran = threading.Event()
|
||||
start_timer(0.2, ran.set)()
|
||||
self.assertFalse(ran.wait(0.5))
|
||||
|
||||
def test_stopping_a_timer_whose_action_runs_waits_for_the_action_to_end(self):
|
||||
started, ended = threading.Event(), threading.Event()
|
||||
|
||||
def action():
|
||||
started.set()
|
||||
time.sleep(0.2)
|
||||
ended.set()
|
||||
stop = start_timer(0, action)
|
||||
self.assertTrue(started.wait(10))
|
||||
stop()
|
||||
self.assertTrue(ended.is_set())
|
||||
|
||||
Reference in New Issue
Block a user