]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: call sync() before checking the test logs
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 17 Oct 2022 16:11:21 +0000 (18:11 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 17 Oct 2022 20:24:24 +0000 (20:24 +0000)
Otherwise we might hit a race where we read the test log just before
it's fully written to the disk:

```
======================================================================
FAIL: test_interleaved (__main__.ExecutionResumeTest.test_interleaved)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/systemd/test/test-exec-deserialization.py", line 170, in test_interleaved
    self.check_output(expected_output)
  File "/root/systemd/test/test-exec-deserialization.py", line 111, in check_output
    self.assertEqual(output, expected_output)
AssertionError: 'foo\n' != 'foo\nbar\n'
  foo
+ bar
```

With some debug:
```
test_interleaved (__main__.ExecutionResumeTest.test_interleaved) ...
Assertion failed; file contents just after the assertion:
b'foo\n'

File contents 5 seconds later:
b'foo\nbar\n'
FAIL
```

Seen quite often in CentOS CI on the fast baremetal machines.

test/test-exec-deserialization.py

index 8ad343f73df7799854269e9ec8b6d951b5443245..a5afaf547ca73c1cd5fdf3519b635c776c3d050d 100755 (executable)
@@ -104,6 +104,8 @@ class ExecutionResumeTest(unittest.TestCase):
             if subprocess.call(['systemctl', '-q', 'is-active', self.unit]) == 0:
                 continue
 
+            os.sync()
+
             try:
                 with open(self.output_file, 'r', encoding='utf-8') as log:
                     output = log.read()