def test_start_with_callback(bus):
    """Test that callback fires on bus start."""
    try:
        events = []

        def f(*args, **kwargs):  # pylint: disable=invalid-name
            events.append(('f', args, kwargs))

        def g():  # pylint: disable=invalid-name
            events.append('g')

        bus.subscribe('start', g)
        bus.start_with_callback(f, (1, 3, 5), {'foo': 'bar'})

        # Give wait() time to run f()
        time.sleep(0.2)

        # The callback method MUST wait for the STARTED state.
        assert bus.state == bus.states.STARTED

        # The callback method MUST run after all start methods.
        assert events == ['g', ('f', (1, 3, 5), {'foo': 'bar'})]
    finally:
        bus.exit()
Test that callback fires on bus start.
cherrypy/test/test_bus.py