| ... | ... | @@ -393,3 +393,48 @@ test "give nonproblematic timestamp" { |
| 393 | 393 | const now_ns = @intCast(i64, time.milliTimestamp() * time.millisecond) - 1000; |
| 394 | 394 | testing.expect(!is_problematic_timestamp(now_ns)); |
| 395 | 395 | } |
| 396 | |
| 397 | test "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 | } |