Skip to content

Commit

Permalink
Do not show internal error when running out of workers
Browse files Browse the repository at this point in the history
Also show the reason of the session being interrupted
in the warnings summary

Fix pytest-dev#435
  • Loading branch information
nicoddemus committed Jun 6, 2019
1 parent a630e55 commit e926022
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 19 deletions.
1 change: 1 addition & 0 deletions changelog/435.bugfix.rst
@@ -0,0 +1 @@
No longer show an internal error when we run out of workers due to crashes.
2 changes: 2 additions & 0 deletions changelog/435.feature.rst
@@ -0,0 +1,2 @@
When the test session is interrupted due to running out of workers, the reason is shown in the test summary
for easier viewing.
21 changes: 16 additions & 5 deletions src/xdist/dsession.py
Expand Up @@ -49,6 +49,9 @@ def __init__(self, config):
self._max_worker_restart = self.config.option.maxworkerrestart
if self._max_worker_restart is not None:
self._max_worker_restart = int(self._max_worker_restart)

# summary message to print at the end of the session
self._summary_report = None
try:
self.terminal = config.pluginmanager.getplugin("terminalreporter")
except KeyError:
Expand Down Expand Up @@ -198,15 +201,23 @@ def worker_errordown(self, node, error):
)
if maximum_reached:
if self._max_worker_restart == 0:
msg = "Worker restarting disabled"
msg = "worker {} crashed and worker restarting disabled".format(
node.gateway.id
)
else:
msg = "Maximum crashed workers reached: %d" % self._max_worker_restart
self.report_line(msg)
msg = "maximum crashed workers reached: %d" % self._max_worker_restart
self._summary_report = msg
self.report_line("\n" + msg)
self.triggershutdown()
else:
self.report_line("Replacing crashed worker %s" % node.gateway.id)
self.report_line("\nreplacing crashed worker %s" % node.gateway.id)
self._clone_node(node)
self._active_nodes.remove(node)

def pytest_terminal_summary(self, terminalreporter):
if self.config.option.verbose >= 0 and self._summary_report:
terminalreporter.write_sep("=", "xdist: {}".format(self._summary_report))

def worker_collectionfinish(self, node, ids):
"""worker has finished test collection.
Expand Down Expand Up @@ -316,7 +327,7 @@ def handle_crashitem(self, nodeid, worker):
# XXX count no of failures and retry N times
runner = self.config.pluginmanager.getplugin("runner")
fspath = nodeid.split("::")[0]
msg = "Worker %r crashed while running %r" % (worker.gateway.id, nodeid)
msg = "worker %r crashed while running %r" % (worker.gateway.id, nodeid)
rep = runner.TestReport(
nodeid, (fspath, None, fspath), (), "failed", msg, "???"
)
Expand Down
53 changes: 39 additions & 14 deletions testing/acceptance_test.py
Expand Up @@ -849,8 +849,8 @@ def test_b(): pass
res = testdir.runpytest(f, "-n1")
res.stdout.fnmatch_lines(
[
"*Replacing crashed worker*",
"*Worker*crashed while running*",
"replacing crashed worker gw*",
"worker*crashed while running*",
"*1 failed*1 passed*",
]
)
Expand All @@ -868,8 +868,8 @@ def test_d(): pass
res = testdir.runpytest(f, "-n2")
res.stdout.fnmatch_lines(
[
"*Replacing crashed worker*",
"*Worker*crashed while running*",
"replacing crashed worker gw*",
"worker*crashed while running*",
"*1 failed*3 passed*",
]
)
Expand All @@ -885,8 +885,8 @@ def test_b(): pass
res = testdir.runpytest(f, "--dist=each", "--tx=popen")
res.stdout.fnmatch_lines(
[
"*Replacing crashed worker*",
"*Worker*crashed while running*",
"replacing crashed worker gw*",
"worker*crashed while running*",
"*1 failed*1 passed*",
]
)
Expand Down Expand Up @@ -922,14 +922,35 @@ def test_d(): pass
res = testdir.runpytest(f, "-n4", "--max-worker-restart=1")
res.stdout.fnmatch_lines(
[
"*Replacing crashed worker*",
"*Maximum crashed workers reached: 1*",
"*Worker*crashed while running*",
"*Worker*crashed while running*",
"replacing crashed worker*",
"maximum crashed workers reached: 1*",
"worker*crashed while running*",
"worker*crashed while running*",
"*2 failed*2 passed*",
]
)

def test_max_worker_restart_tests_queued(self, testdir):
f = testdir.makepyfile(
"""
import os, pytest
@pytest.mark.parametrize('i', range(10))
def test(i): os._exit(1)
"""
)
res = testdir.runpytest(f, "-n2", "--max-worker-restart=3")
res.stdout.fnmatch_lines(
[
"replacing crashed worker*",
"maximum crashed workers reached: 3*",
"worker*crashed while running*",
"worker*crashed while running*",
"* xdist: maximum crashed workers reached: 3 *",
"* 4 failed in *",
]
)
assert "INTERNALERROR" not in res.stdout.str()

def test_max_worker_restart_die(self, testdir):
f = testdir.makepyfile(
"""
Expand All @@ -939,7 +960,10 @@ def test_max_worker_restart_die(self, testdir):
)
res = testdir.runpytest(f, "-n4", "--max-worker-restart=0")
res.stdout.fnmatch_lines(
["*Unexpectedly no active workers*", "*INTERNALERROR*"]
[
"* xdist: worker gw* crashed and worker restarting disabled *",
"* no tests ran in *",
]
)

def test_disable_restart(self, testdir):
Expand All @@ -954,9 +978,10 @@ def test_c(): pass
res = testdir.runpytest(f, "-n4", "--max-worker-restart=0")
res.stdout.fnmatch_lines(
[
"*Worker restarting disabled*",
"*Worker*crashed while running*",
"*1 failed*2 passed*",
"worker gw* crashed and worker restarting disabled",
"*worker*crashed while running*",
"* xdist: worker gw* crashed and worker restarting disabled *",
"* 1 failed, 2 passed in *",
]
)

Expand Down

0 comments on commit e926022

Please sign in to comment.