Skip to content

Commit

Permalink
Added unit test and used stop_timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Neff <[email protected]>
  • Loading branch information
andyneff authored and shin- committed Nov 1, 2017
1 parent 2df3d6f commit 0e4bd32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 2 additions & 3 deletions compose/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from docker.errors import ImageNotFound
from docker.errors import NotFound
from docker.types import LogConfig
from docker.utils import version_lt
from docker.utils import version_gte
from docker.utils import version_lt
from docker.utils.ports import build_port_bindings
from docker.utils.ports import split_port
from docker.utils.utils import convert_tmpfs_mounts
Expand Down Expand Up @@ -762,8 +762,7 @@ def _get_container_create_options(

if (version_gte(self.client.api_version, '1.25') and
'stop_grace_period' in self.options):
container_options['stop_timeout'] = parse_seconds_float(
self.options.pop('stop_grace_period'))
container_options['stop_timeout'] = self.stop_timeout(None)

if 'ports' in container_options or 'expose' in self.options:
container_options['ports'] = build_container_ports(
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ def test_log_opt(self):
{'Type': 'syslog', 'Config': {'syslog-address': 'tcp://192.168.0.42:123'}}
)

def test_stop_grace_period(self):
self.mock_client.api_version = '1.25'
self.mock_client.create_host_config.return_value = {}
service = Service(
'foo',
image='foo',
client=self.mock_client,
stop_grace_period="1m35s")
opts = service._get_container_create_options({'image': 'foo'}, 1)
self.assertEqual(opts['stop_timeout'], 95)

def test_split_domainname_none(self):
service = Service(
'foo',
Expand Down

0 comments on commit 0e4bd32

Please sign in to comment.