def test_wait(bus):
    """Test that bus wait awaits for states."""

    def f(method):  # pylint: disable=invalid-name
        time.sleep(0.2)
        getattr(bus, method)()

    flow = [
        ('start', [bus.states.STARTED]),
        ('stop', [bus.states.STOPPED]),
        ('start', [bus.states.STARTING, bus.states.STARTED]),
        ('exit', [bus.states.EXITING]),
    ]

    for method, states in flow:
        threading.Thread(target=f, args=(method,)).start()
        bus.wait(states)

        # The wait method MUST wait for the given state(s).
        assert bus.state in states, 'State %r not in %r' % (bus.state, states)
Test that bus wait awaits for states.
cherrypy/test/test_bus.py