Skip to content

Commit f466cc3

Browse files
committed
tests: Add first_stage_test that completes the first stage
Add a test that completes the first stage without any error. Signed-off-by: Marc Hartmayer <[email protected]>
1 parent 7be79d0 commit f466cc3

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/first_stage_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,44 @@ def test_valid_syntax(self):
5050
)
5151
finally:
5252
fp.close()
53+
54+
def test_stage(self):
55+
options = mitogen.parent.Options(max_message_size=123)
56+
conn = mitogen.parent.Connection(options, self.router)
57+
conn.context = mitogen.core.Context(None, 123)
58+
args = conn.get_boot_command()
59+
preamble = conn.get_preamble()
60+
61+
# The boot command should write all ECO markers to stdout, read the
62+
# preamble from stdin, then execute it.
63+
64+
# This test writes the preamble to STDIN and closes it then to create an
65+
# EOF situation.
66+
# 1. Fork child tries to read from STDIN, but stops as EOF is received.
67+
# 2. Fork child writes all ECO markers to stdout
68+
# TBD
69+
70+
proc = mitogen.parent.popen(args=args,
71+
stdout=subprocess.PIPE,
72+
stderr=subprocess.PIPE,
73+
stdin=subprocess.PIPE,
74+
)
75+
try:
76+
try:
77+
stdout, stderr = proc.communicate(input=preamble, timeout=10)
78+
except TypeError:
79+
stdout, stderr = proc.communicate(input=preamble)
80+
except:
81+
proc.kill()
82+
self.fail("First stage did not finish")
83+
else:
84+
# proc was killed by SIGTERM?!? TODO Where does this come from?
85+
self.assertEqual(-15, proc.returncode)
86+
self.assertEqual(stdout,
87+
mitogen.parent.BootstrapProtocol.EC0_MARKER + b('\n') +
88+
mitogen.parent.BootstrapProtocol.EC1_MARKER + b('\n') +
89+
mitogen.parent.BootstrapProtocol.EC2_MARKER + b('\n'))
90+
self.assertEqual(
91+
b(""),
92+
stderr,
93+
)

0 commit comments

Comments
 (0)