test: give systemd chance to actually start the unit
In certain cases the expected enqueue-start-replace-continue
sequence would end up as enqueue-replace-start-continue which causes
unexpected fails even though the serialization/deserialization part
works as expected. As we can't use `--wait` in this case, let's give
sysetmd a second to actually start the unit before replacing it with
another one.
Also, switch from the single-letter test output to a bit verbose format.
Fixes: #14632
diff --git a/test/test-exec-deserialization.py b/test/test-exec-deserialization.py
index a11c5ec..8aa16fb 100755
--- a/test/test-exec-deserialization.py
+++ b/test/test-exec-deserialization.py
@@ -11,6 +11,7 @@
import os
import tempfile
import subprocess
+import sys
from enum import Enum
@@ -32,7 +33,7 @@
unit_file_content = '''
[Service]
Type=oneshot
- ExecStart=/bin/sleep 2
+ ExecStart=/bin/sleep 3
ExecStart=/bin/bash -c "echo foo >> {0}"
'''.format(self.output_file)
self.unit_files[UnitFileChange.NO_CHANGE] = unit_file_content
@@ -41,7 +42,7 @@
[Service]
Type=oneshot
ExecStart=/bin/bash -c "echo foo >> {0}"
- ExecStart=/bin/sleep 2
+ ExecStart=/bin/sleep 3
'''.format(self.output_file)
self.unit_files[UnitFileChange.LINES_SWAPPED] = unit_file_content
@@ -49,7 +50,7 @@
[Service]
Type=oneshot
ExecStart=/bin/bash -c "echo bar >> {0}"
- ExecStart=/bin/sleep 2
+ ExecStart=/bin/sleep 3
ExecStart=/bin/bash -c "echo foo >> {0}"
'''.format(self.output_file)
self.unit_files[UnitFileChange.COMMAND_ADDED_BEFORE] = unit_file_content
@@ -57,7 +58,7 @@
unit_file_content = '''
[Service]
Type=oneshot
- ExecStart=/bin/sleep 2
+ ExecStart=/bin/sleep 3
ExecStart=/bin/bash -c "echo foo >> {0}"
ExecStart=/bin/bash -c "echo bar >> {0}"
'''.format(self.output_file)
@@ -67,7 +68,7 @@
[Service]
Type=oneshot
ExecStart=/bin/bash -c "echo baz >> {0}"
- ExecStart=/bin/sleep 2
+ ExecStart=/bin/sleep 3
ExecStart=/bin/bash -c "echo foo >> {0}"
ExecStart=/bin/bash -c "echo bar >> {0}"
'''.format(self.output_file)
@@ -107,6 +108,7 @@
def setup_unit(self):
self.write_unit_file(UnitFileChange.NO_CHANGE)
subprocess.check_call(['systemctl', '--job-mode=replace', '--no-block', 'start', self.unit])
+ time.sleep(1)
def test_no_change(self):
expected_output = 'foo\n'
@@ -207,4 +209,4 @@
self.reload()
if __name__ == '__main__':
- unittest.main()
+ unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=3))