nameko.testing.pytest¶
Functions¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This fixture fixes the order of the container_factory, runner_factory |
|
|
|
|
|
|
|
|
|
|
|
Module Contents¶
- nameko.testing.pytest.fast_teardown(request)[源代码]¶
This fixture fixes the order of the container_factory, runner_factory and rabbit_config fixtures to get the fastest possible teardown of tests that use them.
Without this fixture, the teardown order depends on the fixture resolution defined by the test, for example:
- def test_foo(container_factory, rabbit_config):
pass # rabbit_config tears down first
- def test_bar(rabbit_config, container_factory):
pass # container_factory tears down first
This fixture ensures the teardown order is:
fast_teardown (this fixture)
rabbit_config
container_factory / runner_factory
That is, rabbit_config teardown, which removes the vhost created for the test, happens before the consumers are stopped.
Deleting the vhost causes the broker to sends a "basic-cancel" message to any connected consumers, which will include the consumers in all containers created by the container_factory and runner_factory fixtures.
This speeds up test teardown because the "basic-cancel" breaks the consumers' drain_events loop (http://bit.do/kombu-drain-events) which would otherwise wait for up to a second for the socket read to time out before gracefully shutting down.
For even faster teardown, we monkeypatch the consumers to ensure they don't try to reconnect between the "basic-cancel" and being explicitly stopped when their container is killed.
In older versions of RabbitMQ, the monkeypatch also protects against a race-condition that can lead to hanging tests.
Modern RabbitMQ raises a NotAllowed exception if you try to connect to a vhost that doesn't exist, but older versions (including 3.4.3, used by Travis) just raise a socket.error. This is classed as a recoverable error, and consumers attempt to reconnect. Kombu's reconnection code blocks until a connection is established, so consumers that attempt to reconnect before being killed get stuck there.