Skip to content

Commit 0127a5f

Browse files
committed
first_stage_test: Add test_timeout_error
Signed-off-by: Marc Hartmayer <[email protected]>
1 parent d71a4d3 commit 0127a5f

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/first_stage_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fcntl
22
import functools
33
import operator
4+
import sys
45

56
import mitogen.core
67
import mitogen.parent
@@ -210,3 +211,35 @@ def test_eof_too_early(self):
210211
finally:
211212
proc.stdout.close()
212213
proc.stderr.close()
214+
215+
def test_timeout_error(self):
216+
"""
217+
The boot command should write an ECO marker to stdout, read the
218+
preamble from stdin, then execute it.
219+
220+
This test attaches closes stdin to create a specific failure
221+
1. Fork child tries to read from STDIN, but fails as it is closed
222+
2. Fork child raises TimeoutError
223+
3. Fork child's file descriptors (write pipes) are closed by the OS
224+
4. Fork parent does `dup(<read pipe>, <stdin>)` and `exec(<python>)`
225+
5. Python reads `b''` (i.e. EOF) from stdin (a closed pipe)
226+
6. Python runs `''` (a valid script) and exits with success
227+
"""
228+
229+
proc = testlib.subprocess.Popen(
230+
args=self.args,
231+
stdout=testlib.subprocess.PIPE,
232+
stderr=testlib.subprocess.PIPE,
233+
preexec_fn=sys.stdin.close,
234+
)
235+
try:
236+
stdout, stderr = proc.communicate(timeout=12)
237+
except testlib.subprocess.TimeoutExpired:
238+
proc.kill()
239+
self.fail("Timeout situation was not recognized")
240+
self.assertEqual(0, proc.returncode)
241+
self.assertEqual(stdout, mitogen.parent.BootstrapProtocol.EC0_MARKER + b("\n"))
242+
self.assertIn(
243+
b("TimeoutError"),
244+
stderr,
245+
)

0 commit comments

Comments
 (0)