| ... | ... | @@ -466,7 +466,16 @@ fn isProblematicTimestamp(fs_clock: i128) bool { |
| 466 | 466 | } else { |
| 467 | 467 | wall_nsec &= @as(i64, -1) << @intCast(u6, @ctz(i64, fs_nsec)); |
| 468 | 468 | } |
| 469 | | return wall_nsec == fs_nsec and wall_sec == fs_sec; |
| 469 | if (wall_nsec == fs_nsec and wall_sec == fs_sec) |
| 470 | return true; |
| 471 | |
| 472 | // I have also observed precision problems at a millisecond granularity. |
| 473 | const fs_msec = @intCast(i64, @divFloor(fs_clock, std.time.ns_per_ms * 2)); |
| 474 | const wall_msec = @intCast(i64, @divFloor(wall_clock, std.time.ns_per_ms * 2)); |
| 475 | if (fs_msec == wall_msec) |
| 476 | return true; |
| 477 | |
| 478 | return false; |
| 470 | 479 | } |
| 471 | 480 | |
| 472 | 481 | test "cache file and then recall it" { |
| ... | ... | @@ -479,9 +488,10 @@ test "cache file and then recall it" { |
| 479 | 488 | const temp_file = "test.txt"; |
| 480 | 489 | const temp_manifest_dir = "temp_manifest_dir"; |
| 481 | 490 | |
| 491 | const ts = std.time.nanoTimestamp(); |
| 482 | 492 | try cwd.writeFile(temp_file, "Hello, world!\n"); |
| 483 | 493 | |
| 484 | | while (isProblematicTimestamp(std.time.nanoTimestamp())) { |
| 494 | while (isProblematicTimestamp(ts)) { |
| 485 | 495 | std.time.sleep(1); |
| 486 | 496 | } |
| 487 | 497 | |
| ... | ... | @@ -545,9 +555,13 @@ test "check that changing a file makes cache fail" { |
| 545 | 555 | const original_temp_file_contents = "Hello, world!\n"; |
| 546 | 556 | const updated_temp_file_contents = "Hello, world; but updated!\n"; |
| 547 | 557 | |
| 558 | try cwd.deleteTree(temp_manifest_dir); |
| 559 | try cwd.deleteTree(temp_file); |
| 560 | |
| 561 | const ts = std.time.nanoTimestamp(); |
| 548 | 562 | try cwd.writeFile(temp_file, original_temp_file_contents); |
| 549 | 563 | |
| 550 | | while (isProblematicTimestamp(std.time.nanoTimestamp())) { |
| 564 | while (isProblematicTimestamp(ts)) { |
| 551 | 565 | std.time.sleep(1); |
| 552 | 566 | } |
| 553 | 567 | |
| ... | ... | @@ -571,10 +585,6 @@ test "check that changing a file makes cache fail" { |
| 571 | 585 | |
| 572 | 586 | try cwd.writeFile(temp_file, updated_temp_file_contents); |
| 573 | 587 | |
| 574 | | while (isProblematicTimestamp(std.time.nanoTimestamp())) { |
| 575 | | std.time.sleep(1); |
| 576 | | } |
| 577 | | |
| 578 | 588 | { |
| 579 | 589 | var ch = try CacheHash.init(testing.allocator, cwd, temp_manifest_dir); |
| 580 | 590 | defer ch.release(); |
| ... | ... | @@ -594,7 +604,7 @@ test "check that changing a file makes cache fail" { |
| 594 | 604 | testing.expect(!mem.eql(u8, digest1[0..], digest2[0..])); |
| 595 | 605 | |
| 596 | 606 | try cwd.deleteTree(temp_manifest_dir); |
| 597 | | try cwd.deleteFile(temp_file); |
| 607 | try cwd.deleteTree(temp_file); |
| 598 | 608 | } |
| 599 | 609 | |
| 600 | 610 | test "no file inputs" { |
| ... | ... | @@ -643,10 +653,11 @@ test "CacheHashes with files added after initial hash work" { |
| 643 | 653 | const temp_file2 = "cache_hash_post_file_test2.txt"; |
| 644 | 654 | const temp_manifest_dir = "cache_hash_post_file_manifest_dir"; |
| 645 | 655 | |
| 656 | const ts1 = std.time.nanoTimestamp(); |
| 646 | 657 | try cwd.writeFile(temp_file1, "Hello, world!\n"); |
| 647 | 658 | try cwd.writeFile(temp_file2, "Hello world the second!\n"); |
| 648 | 659 | |
| 649 | | while (isProblematicTimestamp(std.time.nanoTimestamp())) { |
| 660 | while (isProblematicTimestamp(ts1)) { |
| 650 | 661 | std.time.sleep(1); |
| 651 | 662 | } |
| 652 | 663 | |
| ... | ... | @@ -680,9 +691,10 @@ test "CacheHashes with files added after initial hash work" { |
| 680 | 691 | testing.expect(mem.eql(u8, &digest1, &digest2)); |
| 681 | 692 | |
| 682 | 693 | // Modify the file added after initial hash |
| 694 | const ts2 = std.time.nanoTimestamp(); |
| 683 | 695 | try cwd.writeFile(temp_file2, "Hello world the second, updated\n"); |
| 684 | 696 | |
| 685 | | while (isProblematicTimestamp(std.time.nanoTimestamp())) { |
| 697 | while (isProblematicTimestamp(ts2)) { |
| 686 | 698 | std.time.sleep(1); |
| 687 | 699 | } |
| 688 | 700 | |