11import subprocess
22
3+ import mitogen .core
34import mitogen .parent
45from mitogen .core import b
56
@@ -21,14 +22,18 @@ def test_valid_syntax(self):
2122 conn .context = mitogen .core .Context (None , 123 )
2223 args = conn .get_boot_command ()
2324
24- # Executing the boot command will print "EC0" and expect to read from
25- # stdin, which will fail because it's pointing at /dev/null, causing
26- # the forked child to crash with an EOFError and disconnect its write
27- # pipe. The forked and freshly execed parent will get a 0-byte read
28- # from the pipe, which is a valid script, and therefore exit indicating
29- # success.
25+ # The boot command should write an ECO marker to stdout, read the
26+ # preamble from stdin, then execute it.
3027
31- fp = open ("/dev/null" , "r" )
28+ # This test attaches /dev/zero to stdin to create a specific failure
29+ # 1. Fork child reads PREAMBLE_COMPRESSED_LEN bytes of junk (all `\0`)
30+ # 2. Fork child crashes (trying to decompress the junk data)
31+ # 3. Fork child's file descriptors (write pipes) are closed by the OS
32+ # 4. Fork parent does `dup(<read pipe>, <stdin>)` and `exec(<python>)`
33+ # 5. Python reads `b''` (i.e. EOF) from stdin (a closed pipe)
34+ # 6. Python runs `''` (a valid script) and exits with success
35+
36+ fp = open ("/dev/zero" , "r" )
3237 try :
3338 proc = subprocess .Popen (args ,
3439 stdin = fp ,
@@ -39,6 +44,9 @@ def test_valid_syntax(self):
3944 self .assertEqual (0 , proc .returncode )
4045 self .assertEqual (stdout ,
4146 mitogen .parent .BootstrapProtocol .EC0_MARKER + b ('\n ' ))
42- self .assertIn (b ("Error -5 while decompressing data" ), stderr )
47+ self .assertIn (
48+ b ("Error -3 while decompressing data" ), # Unknown compression method
49+ stderr ,
50+ )
4351 finally :
4452 fp .close ()
0 commit comments