Skip to content

Commit d2a1f7e

Browse files
committed
Fix some tests that fail under GitHub CI
1 parent ba46e1b commit d2a1f7e

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

testing/__init__.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ def child_pids(pid):
5252
for p in LocalPath('/proc').listdir():
5353
try:
5454
stat = open(p.join('stat').strpath).read()
55-
m = re.match(r'^\d+ \(.+?\) [a-zA-Z] (\d+) ', stat)
55+
m = re.match(
56+
r'^\d+ \(.+?\) '
57+
# This field, state, is normally a single letter, but can be
58+
# "0" if there are some unusual security settings that prevent
59+
# reading the process state (happens under GitHub Actions with
60+
# QEMU for some reason).
61+
'[0a-zA-Z] '
62+
r'(\d+) ',
63+
stat,
64+
)
5665
assert m, stat
5766
ppid = int(m.group(1))
5867
if ppid == pid:

tests/cli_test.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,34 @@ def current_version():
1212
return open('VERSION').read().strip()
1313

1414

15+
def normalize_stderr(stderr):
16+
# dumb-init prints out argv[0] in its usage message. This should always be
17+
# just "dumb-init" under regular test scenarios here since that is how we
18+
# call it, but in CI the use of QEMU causes the argv[0] to be replaced with
19+
# the full path.
20+
#
21+
# This is supposed to be avoidable by:
22+
# 1) Setting the "P" flag in the binfmt register:
23+
# https://en.wikipedia.org/wiki/Binfmt_misc#Registration
24+
# This can be done by setting the QEMU_PRESERVE_PARENT env var when
25+
# calling binfmt.
26+
#
27+
# 2) Setting the "QEMU_ARGV0" env var to empty string for *all*
28+
# processes:
29+
# https://bugs.launchpad.net/qemu/+bug/1835839
30+
#
31+
# I can get it working properly in CI outside of Docker, but for some
32+
# reason not during Docker builds. This doesn't affect the built executable
33+
# so I decided to just punt on it.
34+
return re.sub(rb'(^|(?<=\s))[a-z/.]+/dumb-init', b'dumb-init', stderr)
35+
36+
1537
@pytest.mark.usefixtures('both_debug_modes', 'both_setsid_modes')
1638
def test_no_arguments_prints_usage():
1739
proc = Popen(('dumb-init'), stderr=PIPE)
1840
_, stderr = proc.communicate()
1941
assert proc.returncode != 0
20-
assert stderr == (
42+
assert normalize_stderr(stderr) == (
2143
b'Usage: dumb-init [option] program [args]\n'
2244
b'Try dumb-init --help for full usage.\n'
2345
)
@@ -28,7 +50,7 @@ def test_exits_invalid_with_invalid_args():
2850
proc = Popen(('dumb-init', '--yolo', '/bin/true'), stderr=PIPE)
2951
_, stderr = proc.communicate()
3052
assert proc.returncode == 1
31-
assert stderr in (
53+
assert normalize_stderr(stderr) in (
3254
b"dumb-init: unrecognized option '--yolo'\n", # glibc
3355
b'dumb-init: unrecognized option: yolo\n', # musl
3456
)
@@ -43,7 +65,7 @@ def test_help_message(flag, current_version):
4365
proc = Popen(('dumb-init', flag), stderr=PIPE)
4466
_, stderr = proc.communicate()
4567
assert proc.returncode == 0
46-
assert stderr == (
68+
assert normalize_stderr(stderr) == (
4769
b'dumb-init v' + current_version.encode('ascii') + b'\n'
4870
b'Usage: dumb-init [option] command [[arg] ...]\n'
4971
b'\n'

0 commit comments

Comments
 (0)