compose/tests/unit
Alberto Piai 394c8efe98 fix race condition in Service.create_container()
The Service.create_container() method fetches a list of the current
containers in order to determine the next container number. In doing so,
it makes several API calls: one to fetch the list of containers, then
one per container in order to inspect it.

In some situations it can happen that a container is removed after
having been listed: in that case, the call to inspect will get a 404 and
raise a NotFound.

One situation in which this has been observed is when trying to
concurrently create multiple one-off containers for the same service
(using `docker-compose run` and a unique `--name`), as described in
more detail in gh-5179.

This patch adds a unit test that simulates the race between the
calls to list and to inspect, and changes Service._next_container_number
to skip removed containers instead of blowing up.

Fixes gh-5179

Signed-off-by: Alberto Piai <apiai@sensational.ch>
2018-03-27 10:21:15 +02:00
..
cli Re-use TLS and host options when shelling out to docker CLI 2018-02-27 11:14:28 -08:00
config Preserve security_opt values in extends 2018-03-08 18:03:54 -08:00
__init__.py Split tests into unit and integration 2014-04-25 22:58:21 +01:00
bundle_test.py Use mock compatibility import 2018-01-22 23:10:50 -06:00
cli_test.py Allow dash and underscore in project name. 2018-03-15 15:44:43 +01:00
container_test.py Add health string generator to match `docker ps` output 2018-02-12 12:10:05 -08:00
network_test.py Network label mismatch now prints a warning instead of raising an error 2017-05-23 15:26:17 -07:00
parallel_test.py Revamp ParallelStreamWriter to fix display issues. 2018-03-07 15:22:38 +01:00
progress_stream_test.py Manage encoding errors in progress_stream 2018-03-15 17:10:36 -07:00
project_test.py Use configfile-provided proxy values to populate buildargs and env values 2018-02-22 16:19:50 -08:00
service_test.py fix race condition in Service.create_container() 2018-03-27 10:21:15 +02:00
split_buffer_test.py Replace unittest-style asserts with pytest asserts 2018-01-04 14:38:28 -08:00
timeparse_test.py Use stop grace period for container stop. 2016-11-16 12:12:28 -05:00
utils_test.py Avoid import ConfigurationError inside compose.utils (circular import) 2017-09-28 16:51:03 -07:00
volume_test.py Add support for v3.4 files and custom volume names 2017-08-11 11:48:00 -07:00