Skip to content

Commit 62e2d98

Browse files
authored
Merge pull request #5015 from stsewd/keep-cmd-output-when-killed
Keep command output when it's killed
2 parents 5d4da21 + 2756866 commit 62e2d98

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

readthedocs/doc_builder/environments.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
"""Documentation Builder Environments."""
44

55
from __future__ import (
6-
absolute_import, division, print_function, unicode_literals)
6+
absolute_import,
7+
division,
8+
print_function,
9+
unicode_literals,
10+
)
711

812
import logging
9-
import json
1013
import os
1114
import re
1215
import socket
@@ -32,13 +35,28 @@
3235
from readthedocs.restapi.client import api as api_v2
3336

3437
from .constants import (
35-
DOCKER_HOSTNAME_MAX_LEN, DOCKER_IMAGE, DOCKER_LIMITS, DOCKER_OOM_EXIT_CODE,
36-
DOCKER_SOCKET, DOCKER_TIMEOUT_EXIT_CODE, DOCKER_VERSION,
37-
MKDOCS_TEMPLATE_DIR, SPHINX_TEMPLATE_DIR)
38+
DOCKER_HOSTNAME_MAX_LEN,
39+
DOCKER_IMAGE,
40+
DOCKER_LIMITS,
41+
DOCKER_OOM_EXIT_CODE,
42+
DOCKER_SOCKET,
43+
DOCKER_TIMEOUT_EXIT_CODE,
44+
DOCKER_VERSION,
45+
MKDOCS_TEMPLATE_DIR,
46+
SPHINX_TEMPLATE_DIR,
47+
)
3848
from .exceptions import (
39-
BuildEnvironmentCreationFailed, BuildEnvironmentError,
40-
BuildEnvironmentException, BuildEnvironmentWarning, BuildTimeoutError,
41-
ProjectBuildsSkippedError, VersionLockedError, YAMLParseError, MkDocsYAMLParseError)
49+
BuildEnvironmentCreationFailed,
50+
BuildEnvironmentError,
51+
BuildEnvironmentException,
52+
BuildEnvironmentWarning,
53+
BuildTimeoutError,
54+
MkDocsYAMLParseError,
55+
ProjectBuildsSkippedError,
56+
VersionLockedError,
57+
YAMLParseError,
58+
)
59+
4260

4361
log = logging.getLogger(__name__)
4462

@@ -295,8 +313,9 @@ def run(self):
295313
# is in the last 15 lines of the command's output
296314
killed_in_output = 'Killed' in '\n'.join(self.output.splitlines()[-15:])
297315
if self.exit_code == DOCKER_OOM_EXIT_CODE or (self.exit_code == 1 and killed_in_output):
298-
self.output = _('Command killed due to excessive memory '
299-
'consumption\n')
316+
self.output += str(_(
317+
'\n\nCommand killed due to excessive memory consumption\n'
318+
))
300319
except DockerAPIError:
301320
self.exit_code = -1
302321
if self.output is None or not self.output:

readthedocs/rtd_tests/tests/test_doc_building.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
* the Command wrappers encapsulate the bytes and expose unicode
77
"""
88
from __future__ import (
9-
absolute_import, division, print_function, unicode_literals)
9+
absolute_import,
10+
division,
11+
print_function,
12+
unicode_literals,
13+
)
1014

1115
import json
1216
import os
@@ -27,15 +31,19 @@
2731
from readthedocs.builds.models import Version
2832
from readthedocs.doc_builder.config import load_yaml_config
2933
from readthedocs.doc_builder.environments import (
30-
BuildCommand, DockerBuildCommand, DockerBuildEnvironment,
31-
LocalBuildEnvironment)
34+
BuildCommand,
35+
DockerBuildCommand,
36+
DockerBuildEnvironment,
37+
LocalBuildEnvironment,
38+
)
3239
from readthedocs.doc_builder.exceptions import BuildEnvironmentError
3340
from readthedocs.doc_builder.python_environments import Conda, Virtualenv
3441
from readthedocs.projects.models import Project
3542
from readthedocs.rtd_tests.mocks.environment import EnvironmentMockGroup
3643
from readthedocs.rtd_tests.mocks.paths import fake_paths_lookup
3744
from readthedocs.rtd_tests.tests.test_config_integration import create_load
3845

46+
3947
DUMMY_BUILD_ID = 123
4048
SAMPLE_UNICODE = u'HérÉ îß sömê ünïçó∂é'
4149
SAMPLE_UTF8_BYTES = SAMPLE_UNICODE.encode('utf-8')
@@ -1127,9 +1135,10 @@ def test_command_oom_kill(self):
11271135
cmd.build_env.get_client.return_value = self.mocks.docker_client
11281136
type(cmd.build_env).container_id = PropertyMock(return_value='foo')
11291137
cmd.run()
1130-
self.assertEqual(
1131-
str(cmd.output),
1132-
u'Command killed due to excessive memory consumption\n')
1138+
self.assertIn(
1139+
'Command killed due to excessive memory consumption\n',
1140+
str(cmd.output)
1141+
)
11331142

11341143

11351144
class TestPythonEnvironment(TestCase):

0 commit comments

Comments
 (0)