-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read stderr from layer subprocesses in a thread
If the test runner runs a layer in a subprocess (due to not being able to tear down a previous layer), then the child process communicates the IDs of any tests that fail or error to its parent by a simple protocol over its stderr. However, the parent doesn't start reading this until it's finished reading everything from the child's stdout and its end of the pipe corresponding to the child's stdout signals end-of-file, which isn't going to happen until the child finishes writing everything to stderr and exits. This can result in a deadlock if the child process encounters enough failures or errors that their test IDs overflow the capacity of a pipe, which on Linux >= 2.6.11 is 65536 bytes. To avoid this, read the child's stderr in a thread. (On Unix, we could use select instead, but that doesn't work for pipes on Windows, and we're already using threads here anyway.) Fixes #105.
- Loading branch information
Showing
4 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/zope/testrunner/tests/testrunner-ex/sampletests_many.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2020 Zope Foundation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
"""A large number of sample tests.""" | ||
|
||
import unittest | ||
|
||
|
||
class Layer1: | ||
"""A layer that can't be torn down.""" | ||
|
||
@classmethod | ||
def setUp(self): | ||
pass | ||
|
||
@classmethod | ||
def tearDown(self): | ||
raise NotImplementedError | ||
|
||
|
||
class Layer2: | ||
|
||
@classmethod | ||
def setUp(self): | ||
pass | ||
|
||
@classmethod | ||
def tearDown(self): | ||
pass | ||
|
||
|
||
class TestNoTeardown(unittest.TestCase): | ||
|
||
layer = Layer1 | ||
|
||
def test_something(self): | ||
pass | ||
|
||
|
||
def make_TestMany(): | ||
attrs = {'layer': Layer2} | ||
# Add enough failing test methods to make the concatenation of all their | ||
# test IDs (formatted as "test_foo (sampletests_many.TestMany)") | ||
# overflow the capacity of a pipe. This is system-dependent, but on | ||
# Linux since 2.6.11 it defaults to 65536 bytes, so will overflow by the | ||
# time we've written 874 of these test IDs. If the pipe capacity is | ||
# much larger than that, then this test might be ineffective. | ||
for i in range(1000): | ||
attrs['test_some_very_long_test_name_with_padding_%03d' % i] = ( | ||
lambda self: self.fail()) | ||
return type('TestMany', (unittest.TestCase,), attrs) | ||
|
||
|
||
TestMany = make_TestMany() | ||
|
||
|
||
def test_suite(): | ||
suite = unittest.TestSuite() | ||
suite.addTest(unittest.makeSuite(TestNoTeardown)) | ||
suite.addTest(unittest.makeSuite(TestMany)) | ||
return suite | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters