General testing of a Persistent Store prune calls.
(tmpdir)
| 1375 | sys.platform == "win32", reason="Unreliable results to be determined" |
| 1376 | ) |
| 1377 | def test_persistent_storage_disk_prune(tmpdir): |
| 1378 | """General testing of a Persistent Store prune calls.""" |
| 1379 | |
| 1380 | # Persistent Storage Initialization |
| 1381 | pc = PersistentStore( |
| 1382 | path=str(tmpdir), namespace="t01", mode=PersistentStoreMode.FLUSH |
| 1383 | ) |
| 1384 | # Store some data |
| 1385 | assert pc.write(b"data-t01") is True |
| 1386 | assert pc.set("key-t01", "value") |
| 1387 | |
| 1388 | pc = PersistentStore( |
| 1389 | path=str(tmpdir), namespace="t02", mode=PersistentStoreMode.FLUSH |
| 1390 | ) |
| 1391 | # Store some data |
| 1392 | assert pc.write(b"data-t02") is True |
| 1393 | assert pc.set("key-t02", "value") |
| 1394 | |
| 1395 | # purne anything older then 30s |
| 1396 | results = PersistentStore.disk_prune(path=str(tmpdir), expires=30) |
| 1397 | # Nothing is older then 30s right now |
| 1398 | assert isinstance(results, dict) |
| 1399 | assert "t01" in results |
| 1400 | assert "t02" in results |
| 1401 | assert len(results["t01"]) == 0 |
| 1402 | assert len(results["t02"]) == 0 |
| 1403 | |
| 1404 | pc = PersistentStore( |
| 1405 | path=str(tmpdir), namespace="t01", mode=PersistentStoreMode.FLUSH |
| 1406 | ) |
| 1407 | |
| 1408 | # Nothing is pruned |
| 1409 | assert pc.get("key-t01") == "value" |
| 1410 | assert pc.read() == b"data-t01" |
| 1411 | |
| 1412 | # An expiry of zero gets everything |
| 1413 | # Note: This test randomly fails in Microsoft Windows for unknown reasons |
| 1414 | # When this is determined, this test can be opened back up |
| 1415 | results = PersistentStore.disk_prune(path=str(tmpdir), expires=0) |
| 1416 | # We match everything now |
| 1417 | assert isinstance(results, dict) |
| 1418 | assert "t01" in results |
| 1419 | assert "t02" in results |
| 1420 | assert len(results["t01"]) == 2 |
| 1421 | assert len(results["t02"]) == 2 |
| 1422 | |
| 1423 | # Content is still not removed however because no action was put in place |
| 1424 | pc = PersistentStore( |
| 1425 | path=str(tmpdir), namespace="t02", mode=PersistentStoreMode.FLUSH |
| 1426 | ) |
| 1427 | # Nothing is pruned |
| 1428 | assert pc.get("key-t02") == "value" |
| 1429 | assert pc.read() == b"data-t02" |
| 1430 | pc = PersistentStore( |
| 1431 | path=str(tmpdir), namespace="t01", mode=PersistentStoreMode.FLUSH |
| 1432 | ) |
| 1433 | # Nothing is pruned |
| 1434 | assert pc.get("key-t01") == "value" |
nothing calls this directly
no test coverage detected
searching dependent graphs…