Skip to content

Commit f57c202

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 0d3e070 commit f57c202

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/first_stage_test.py

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

0 commit comments

Comments
 (0)