summaryrefslogtreecommitdiff
path: root/cherrypy/test/test_bus.py
diff options
context:
space:
mode:
Diffstat (limited to 'cherrypy/test/test_bus.py')
-rw-r--r--cherrypy/test/test_bus.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/cherrypy/test/test_bus.py b/cherrypy/test/test_bus.py
index 6026b47e..12a516c9 100644
--- a/cherrypy/test/test_bus.py
+++ b/cherrypy/test/test_bus.py
@@ -1,6 +1,6 @@
import threading
import time
-import unittest
+import unittest.mock
from cherrypy.process import wspbus
@@ -179,12 +179,14 @@ class BusMethodTests(unittest.TestCase):
time.sleep(0.2)
getattr(b, method)()
- for method, states in [('start', [b.states.STARTED]),
- ('stop', [b.states.STOPPED]),
- ('start',
- [b.states.STARTING, b.states.STARTED]),
- ('exit', [b.states.EXITING]),
- ]:
+ flow = [
+ ('start', [b.states.STARTED]),
+ ('stop', [b.states.STOPPED]),
+ ('start', [b.states.STARTING, b.states.STARTED]),
+ ('exit', [b.states.EXITING]),
+ ]
+
+ for method, states in flow:
threading.Thread(target=f, args=(method,)).start()
b.wait(states)
@@ -192,6 +194,18 @@ class BusMethodTests(unittest.TestCase):
if b.state not in states:
self.fail('State %r not in %r' % (b.state, states))
+ def test_wait_publishes_periodically(self):
+ bus = wspbus.Bus()
+ callback = unittest.mock.MagicMock()
+ bus.subscribe('main', callback)
+
+ def set_start():
+ time.sleep(0.05)
+ bus.start()
+ threading.Thread(target=set_start).start()
+ bus.wait(bus.states.STARTED, interval=0.01, channel='main')
+ assert callback.call_count > 3
+
def test_block(self):
b = wspbus.Bus()
self.log(b)