Persistent Storage Forced Write Testing.
(tmpdir)
| 248 | |
| 249 | |
| 250 | def test_persistent_storage_flush_mode(tmpdir): |
| 251 | """Persistent Storage Forced Write Testing.""" |
| 252 | namespace = "abc" |
| 253 | # Create ourselves an attachment object |
| 254 | pc = PersistentStore( |
| 255 | namespace=namespace, path=str(tmpdir), mode=PersistentStoreMode.FLUSH |
| 256 | ) |
| 257 | |
| 258 | # Reference path |
| 259 | path = os.path.join(str(tmpdir), namespace) |
| 260 | |
| 261 | assert pc.size() == 0 |
| 262 | assert list(pc.files()) == [] |
| 263 | |
| 264 | # Key is not set yet |
| 265 | assert pc.get("key") is None |
| 266 | assert len(pc.keys()) == 0 |
| 267 | assert "key" not in pc |
| 268 | |
| 269 | # Verify our data is set |
| 270 | assert pc.set("key", "value") |
| 271 | assert len(pc.keys()) == 1 |
| 272 | assert "key" in list(pc.keys()) |
| 273 | |
| 274 | assert pc.size() > 0 |
| 275 | assert len(pc.files()) == 1 |
| 276 | |
| 277 | # Second call uses Lazy cache |
| 278 | # Just our cache file |
| 279 | assert len(pc.files()) == 1 |
| 280 | |
| 281 | # Setting the same value again uses a lazy mode and |
| 282 | # bypasses all of the write overhead |
| 283 | assert pc.set("key", "value") |
| 284 | |
| 285 | path_content = os.listdir(path) |
| 286 | # var, cache.psdata, and tmp |
| 287 | assert len(path_content) == 3 |
| 288 | |
| 289 | # Assignments (causes another disk write) |
| 290 | pc["key"] = "value2" |
| 291 | |
| 292 | # Setting the same value and explictly marking the field as not being |
| 293 | # perisistent |
| 294 | pc.set("key-xx", "abc123", persistent=False) |
| 295 | # Changing it's value doesn't alter the persistent flag |
| 296 | pc["key-xx"] = "def678" |
| 297 | # Setting it twice |
| 298 | pc["key-xx"] = "def678" |
| 299 | |
| 300 | # Our retrievals |
| 301 | assert pc["key-xx"] == "def678" |
| 302 | assert pc.get("key-xx") == "def678" |
| 303 | |
| 304 | # But on the destruction of our object, it is not available again |
| 305 | del pc |
| 306 | # Create ourselves an attachment object |
| 307 | pc = PersistentStore( |
nothing calls this directly
no test coverage detected
searching dependent graphs…