monitor: fix duration calculation
When fully cached manifest is used, the duration used to print an
incorrect value of 55 years:
python3 -m osbuild --libdir . ./test/data/manifests/fedora-boot.json
⏱ Duration: 1753191578s
This patch fixes the duration calculation to use the correct timestamp
from the manifest by using monotonic timer instead. Additionally, it
prints nothing when there was no module executed. Finally, it improves
the formatting of the duration output.
This commit is contained in:
parent
285a260726
commit
5088c0ee69
2 changed files with 31 additions and 4 deletions
|
|
@ -57,6 +57,31 @@ class TapeMonitor(osbuild.monitor.BaseMonitor):
|
|||
|
||||
|
||||
class TestMonitor(unittest.TestCase):
|
||||
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
|
||||
def test_log_monitor_no_duration(self):
|
||||
index = osbuild.meta.Index(os.curdir)
|
||||
|
||||
runner = Runner(index.detect_host_runner())
|
||||
pipeline = osbuild.Pipeline("pipeline", runner=runner)
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
storedir = os.path.join(tmpdir, "store")
|
||||
|
||||
logfile = os.path.join(tmpdir, "log.txt")
|
||||
|
||||
with open(logfile, "w", encoding="utf8") as log, ObjectStore(storedir) as store:
|
||||
monitor = LogMonitor(log.fileno())
|
||||
res = pipeline.run(store,
|
||||
monitor,
|
||||
libdir=os.path.abspath(os.curdir))
|
||||
monitor.result(res)
|
||||
|
||||
with open(logfile, encoding="utf8") as f:
|
||||
log = f.read()
|
||||
|
||||
assert res
|
||||
self.assertNotIn("Duration", log)
|
||||
|
||||
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
|
||||
def test_log_monitor_vfuncs(self):
|
||||
# Checks the basic functioning of the LogMonitor
|
||||
|
|
@ -86,6 +111,7 @@ class TestMonitor(unittest.TestCase):
|
|||
assert res
|
||||
self.assertIn(pipeline.stages[0].id, log)
|
||||
self.assertIn("isthisthereallife", log)
|
||||
self.assertIn("Duration", log)
|
||||
|
||||
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
|
||||
def test_monitor_integration(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue