1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-08 21:17:47 +03:00

test: call sync() before checking the test logs

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.
This commit is contained in:
Frantisek Sumsal 2022-10-17 18:11:21 +02:00
parent 61938b3c8d
commit 3113ae1f2b

View File

@ -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()