self.reload()
def check_output(self, expected_output):
- try:
- with open(self.output_file, 'r') as log:
- output = log.read()
- except IOError:
- self.fail()
+ for _ in range(15):
+ try:
+ with open(self.output_file, 'r') as log:
+ output = log.read()
+ self.assertEqual(output, expected_output)
+ return
+ except IOError:
+ pass
+
+ time.sleep(1)
- self.assertEqual(output, expected_output)
+ self.fail("Time out while waiting for the output file {} to appear".format(self.output_file))
def setup_unit(self):
self.write_unit_file(UnitFileChange.NO_CHANGE)
self.setup_unit()
self.reload()
- time.sleep(4)
self.check_output(expected_output)
self.setup_unit()
self.write_unit_file(UnitFileChange.LINES_SWAPPED)
self.reload()
- time.sleep(4)
self.assertTrue(not os.path.exists(self.output_file))
self.setup_unit()
self.write_unit_file(UnitFileChange.COMMAND_ADDED_BEFORE)
self.reload()
- time.sleep(4)
self.check_output(expected_output)
self.setup_unit()
self.write_unit_file(UnitFileChange.COMMAND_ADDED_AFTER)
self.reload()
- time.sleep(4)
self.check_output(expected_output)
self.setup_unit()
self.write_unit_file(UnitFileChange.COMMAND_INTERLEAVED)
self.reload()
- time.sleep(4)
self.check_output(expected_output)
self.setup_unit()
self.write_unit_file(UnitFileChange.REMOVAL)
self.reload()
- time.sleep(4)
self.assertTrue(not os.path.exists(self.output_file))
self.reload()
time.sleep(5)
- self.assertTrue(subprocess.call("journalctl -b _PID=1 | grep -q 'Freezing execution'", shell=True) != 0)
+ self.assertTrue(subprocess.call("journalctl -b _PID=1 | grep -q 'Freezing execution'", shell=True) != 0)
def tearDown(self):
for f in [self.output_file, self.unitfile_path]: