'``DockerClient.list`` does not list containers which are removed,
during its operation, from another thread.'

def test_list_removed_containers(self):

    patcher = MonkeyPatcher()
    namespace = namespace_for_test(self)
    flocker_docker_client = DockerClient(namespace=namespace)
    name1 = random_name(self)
    adding_unit1 = flocker_docker_client.add(name1, ANY_IMAGE)
    self.addCleanup(flocker_docker_client.remove, name1)
    name2 = random_name(self)
    adding_unit2 = flocker_docker_client.add(name2, ANY_IMAGE)
    self.addCleanup(flocker_docker_client.remove, name2)
    docker_client = flocker_docker_client._client
    docker_client_containers = docker_client.containers
    def simulate_missing_containers(*args, **kwargs):
        '\n                                                Remove    a    container    before    returning    the    original    list.\n                                                '
        containers = docker_client_containers(*args, **kwargs)
        container_name1 = flocker_docker_client._to_container_name(name1)
        docker_client.remove_container(container=container_name1, force=True)
        return containers
    adding_units = gatherResults([adding_unit1, adding_unit2])
    def get_list(ignored):
        patcher.addPatch(docker_client, 'containers', simulate_missing_containers)
        patcher.patch()
        return flocker_docker_client.list()
    listing_units = adding_units.addCallback(get_list)
    def check_list(units):
        patcher.restore()
        self.assertEqual([name2], sorted([unit.name for unit in units]))
    running_assertions = listing_units.addCallback(check_list)
    return running_assertions
