Skip to content

Commit

Permalink
[tests] Purge expired Status entries
Browse files Browse the repository at this point in the history
  • Loading branch information
tysmith committed Sep 13, 2022
1 parent e2786bf commit 14c4d6d
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions grizzly/common/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def test_status_02(tmp_path):
def test_status_03(tmp_path):
"""test Status.loadall()"""
db_file = str(tmp_path / "status.db")
# load from empty db
assert not any(Status.loadall(db_file))
# create simple entry
status = Status.start(db_file, enable_profiling=True)
status.results.count("uid1", "sig1")
Expand Down Expand Up @@ -96,8 +98,6 @@ def test_status_05(mocker, tmp_path):
fake_time = mocker.patch("grizzly.common.status.time", autospec=True)
fake_time.return_value = 1.0
db_file = str(tmp_path / "status.db")
# load from empty db
assert not any(Status.loadall(db_file))
# create entry
status = Status.start(db_file)
status.results.count("uid1", "sig1")
Expand Down Expand Up @@ -311,6 +311,27 @@ def test_status_09(tmp_path, buckets, ratio, iterations, blockers):
assert len(tuple(status.blockers(iters_per_result=ratio))) == blockers


def test_status_10(mocker, tmp_path):
"""test Status() - purge expired entries"""
fake_time = mocker.patch("grizzly.common.status.time", autospec=True)
db_file = str(tmp_path / "status.db")
# purge due to exp_limit
fake_time.return_value = 1.0
status = Status(db_file=db_file, start_time=1.0, pid=123, exp_limit=10)
status.report(force=True)
assert any(Status.loadall(db_file, time_limit=60))
fake_time.return_value = 20.0
Status(db_file=db_file, start_time=20.0, pid=456, exp_limit=10)
assert not any(Status.loadall(db_file, time_limit=60))
# purge due matching pid
fake_time.return_value = 1.0
status = Status(db_file=db_file, start_time=1.0, pid=123, exp_limit=10)
status.report(force=True)
assert any(Status.loadall(db_file, time_limit=60))
Status(db_file=db_file, start_time=1.0, pid=123, exp_limit=10)
assert not any(Status.loadall(db_file, time_limit=60))


def test_reduce_status_01(mocker, tmp_path):
"""test ReductionStatus()"""
mocker.patch("grizzly.common.status.time", autospec=True, return_value=1.0)
Expand Down Expand Up @@ -672,7 +693,7 @@ def test_report_counter_03(mocker, tmp_path):


def test_report_counter_04(mocker, tmp_path):
"""test ResultCounter remove old entries"""
"""test ResultCounter remove expired entries"""
fake_time = mocker.patch("grizzly.common.status.time", autospec=True)
fake_time.return_value = 1
db_path = str(tmp_path / "storage.db")
Expand Down

0 comments on commit 14c4d6d

Please sign in to comment.