def test__stopping_cancels_start(self):
listener = PostgresListenerService()
# Start then stop immediately, without waiting for start to complete.
starting = listener.startService()
starting_spy = DeferredValue()
starting_spy.observe(starting)
stopping = listener.stopService()
# Both `starting` and `stopping` have callbacks yet to fire.
self.assertThat(starting.callbacks, Not(Equals([])))
self.assertThat(stopping.callbacks, Not(Equals([])))
# Wait for the listener to stop.
yield stopping
# Neither `starting` nor `stopping` have callbacks. This is because
# `stopping` chained itself onto the end of `starting`.
self.assertThat(starting.callbacks, Equals([]))
self.assertThat(stopping.callbacks, Equals([]))
# Confirmation that `starting` was cancelled.
with ExpectedException(CancelledError):
yield starting_spy.get()
评论列表
文章目录