Fix race condition with up and setting signal handlers.
Also print stdout on wait_for_container(). Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
e925b8272b
commit
bbaae11a0f
4 changed files with 44 additions and 35 deletions
|
|
@ -43,7 +43,8 @@ def start_process(base_dir, options):
|
|||
def wait_on_process(proc, returncode=0):
|
||||
stdout, stderr = proc.communicate()
|
||||
if proc.returncode != returncode:
|
||||
print(stderr.decode('utf-8'))
|
||||
print("Stderr: {}".format(stderr))
|
||||
print("Stdout: {}".format(stdout))
|
||||
assert proc.returncode == returncode
|
||||
return ProcessResult(stdout.decode('utf-8'), stderr.decode('utf-8'))
|
||||
|
||||
|
|
@ -81,7 +82,6 @@ class ContainerStateCondition(object):
|
|||
self.name = name
|
||||
self.running = running
|
||||
|
||||
# State.Running == true
|
||||
def __call__(self):
|
||||
try:
|
||||
container = self.client.inspect_container(self.name)
|
||||
|
|
@ -707,6 +707,17 @@ class CLITestCase(DockerClientTestCase):
|
|||
os.kill(proc.pid, signal.SIGTERM)
|
||||
wait_on_condition(ContainerCountCondition(self.project, 0))
|
||||
|
||||
@v2_only()
|
||||
def test_up_handles_force_shutdown(self):
|
||||
self.base_dir = 'tests/fixtures/sleeps-composefile'
|
||||
proc = start_process(self.base_dir, ['up', '-t', '200'])
|
||||
wait_on_condition(ContainerCountCondition(self.project, 2))
|
||||
|
||||
os.kill(proc.pid, signal.SIGTERM)
|
||||
time.sleep(0.1)
|
||||
os.kill(proc.pid, signal.SIGTERM)
|
||||
wait_on_condition(ContainerCountCondition(self.project, 0))
|
||||
|
||||
def test_run_service_without_links(self):
|
||||
self.base_dir = 'tests/fixtures/links-composefile'
|
||||
self.dispatch(['run', 'console', '/bin/true'])
|
||||
|
|
|
|||
10
tests/fixtures/sleeps-composefile/docker-compose.yml
vendored
Normal file
10
tests/fixtures/sleeps-composefile/docker-compose.yml
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
version: 2
|
||||
|
||||
services:
|
||||
simple:
|
||||
image: busybox:latest
|
||||
command: sleep 200
|
||||
another:
|
||||
image: busybox:latest
|
||||
command: sleep 200
|
||||
|
|
@ -6,12 +6,9 @@ import logging
|
|||
from compose import container
|
||||
from compose.cli.errors import UserError
|
||||
from compose.cli.formatter import ConsoleWarningFormatter
|
||||
from compose.cli.log_printer import LogPrinter
|
||||
from compose.cli.main import attach_to_logs
|
||||
from compose.cli.main import build_log_printer
|
||||
from compose.cli.main import convergence_strategy_from_opts
|
||||
from compose.cli.main import setup_console_handler
|
||||
from compose.project import Project
|
||||
from compose.service import ConvergenceStrategy
|
||||
from tests import mock
|
||||
from tests import unittest
|
||||
|
|
@ -49,21 +46,6 @@ class CLIMainTestCase(unittest.TestCase):
|
|||
log_printer = build_log_printer(containers, service_names, True, False)
|
||||
self.assertEqual(log_printer.containers, containers)
|
||||
|
||||
def test_attach_to_logs(self):
|
||||
project = mock.create_autospec(Project)
|
||||
log_printer = mock.create_autospec(LogPrinter, containers=[])
|
||||
service_names = ['web', 'db']
|
||||
timeout = 12
|
||||
|
||||
with mock.patch('compose.cli.main.signals.signal', autospec=True) as mock_signal:
|
||||
attach_to_logs(project, log_printer, service_names, timeout)
|
||||
|
||||
assert mock_signal.signal.mock_calls == [
|
||||
mock.call(mock_signal.SIGINT, mock.ANY),
|
||||
mock.call(mock_signal.SIGTERM, mock.ANY),
|
||||
]
|
||||
log_printer.run.assert_called_once_with()
|
||||
|
||||
|
||||
class SetupConsoleHandlerTestCase(unittest.TestCase):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue