authorgravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-04-14 21:37:35-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-25 13:48:43-04:00
log4254d389d3b21e3c7613c327810b47483b92329b
tree0b4ab257faa7a5ff1e8d49bce749ecdf854a5fad
parentb67a9f2281be6712b299a4dd8bd747d8a5fda882

Add test checking file changes invalidate cache


1 files changed, 45 insertions(+), 0 deletions(-)

lib/std/cache_hash.zig+45
...@@ -393,3 +393,48 @@ test "give nonproblematic timestamp" {...@@ -393,3 +393,48 @@ test "give nonproblematic timestamp" {
393 const now_ns = @intCast(i64, time.milliTimestamp() * time.millisecond) - 1000;393 const now_ns = @intCast(i64, time.milliTimestamp() * time.millisecond) - 1000;
394 testing.expect(!is_problematic_timestamp(now_ns));394 testing.expect(!is_problematic_timestamp(now_ns));
395}395}
396
397test "check that changing a file makes cache fail" {
398 const cwd = fs.cwd();
399
400 const temp_file = "cache_hash_change_file_test.txt";
401 const temp_manifest_dir = "cache_hash_change_file_manifest_dir";
402
403 try cwd.writeFile(temp_file, "Hello, world!\n");
404
405 var digest1: [BASE64_DIGEST_LEN]u8 = undefined;
406 var digest2: [BASE64_DIGEST_LEN]u8 = undefined;
407
408 {
409 var ch = try CacheHash.init(testing.allocator, temp_manifest_dir);
410 defer ch.release();
411
412 ch.add("1234");
413 try ch.addFile(temp_file);
414
415 // There should be nothing in the cache
416 testing.expectEqual(@as(?[64]u8, null), try ch.hit());
417
418 digest1 = ch.final();
419 }
420
421 try cwd.writeFile(temp_file, "Hello, world; but updated!\n");
422
423 {
424 var ch = try CacheHash.init(testing.allocator, temp_manifest_dir);
425 defer ch.release();
426
427 ch.add("1234");
428 try ch.addFile(temp_file);
429
430 // A file that we depend on has been updated, so the cache should not contain an entry for it
431 testing.expectEqual(@as(?[64]u8, null), try ch.hit());
432
433 digest2 = ch.final();
434 }
435
436 testing.expect(!mem.eql(u8, digest1[0..], digest2[0..]));
437
438 try cwd.deleteTree(temp_manifest_dir);
439 try cwd.deleteFile(temp_file);
440}