From 0f4f3ab2c1aad71248e1bea89aefc4b4c0e64589 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 3 Jan 2020 09:04:41 +1000 Subject: [PATCH] speed up two tests the regular test run is now faster than the old parallel one was --- pylib/tests/test_media.py | 11 +++++++---- pylib/tests/test_schedv1.py | 8 +++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pylib/tests/test_media.py b/pylib/tests/test_media.py index 89d595468..a9e907df3 100644 --- a/pylib/tests/test_media.py +++ b/pylib/tests/test_media.py @@ -88,6 +88,10 @@ def test_changes(): def removed(): return d.media.db.execute("select fname from media where csum is null") + def advanceTime(): + d.media.db.execute("update media set mtime=mtime-1") + d.media.db.execute("update meta set dirMod = dirMod - 1") + assert not list(added()) assert not list(removed()) # add a file @@ -95,27 +99,26 @@ def test_changes(): path = os.path.join(dir, "foo.jpg") with open(path, "w") as f: f.write("hello") - time.sleep(1) path = d.media.addFile(path) # should have been logged d.media.findChanges() assert list(added()) assert not list(removed()) # if we modify it, the cache won't notice - time.sleep(1) + advanceTime() with open(path, "w") as f: f.write("world") assert len(list(added())) == 1 assert not list(removed()) # but if we add another file, it will - time.sleep(1) + advanceTime() with open(path + "2", "w") as f: f.write("yo") d.media.findChanges() assert len(list(added())) == 2 assert not list(removed()) # deletions should get noticed too - time.sleep(1) + advanceTime() os.unlink(path + "2") d.media.findChanges() assert len(list(added())) == 1 diff --git a/pylib/tests/test_schedv1.py b/pylib/tests/test_schedv1.py index 14b8982f6..3d24a11d8 100644 --- a/pylib/tests/test_schedv1.py +++ b/pylib/tests/test_schedv1.py @@ -943,9 +943,15 @@ def test_timing(): c = d.sched.getCard() assert c.queue == 2 # but if we wait for a second, the failed card should come back - time.sleep(1) + orig_time = time.time + + def adjusted_time(): + return orig_time() + 1 + + time.time = adjusted_time c = d.sched.getCard() assert c.queue == 1 + time.time = orig_time def test_collapse():