{"thread":{"id":"61903","subject":"[PATCH] t/t7704-repack-cruft.sh: avoid failures during long-running tests","startedAt":"2024-08-05T19:37:14Z","lastAt":"2024-08-05T20:15:22Z","messageCount":2,"participants":["Taylor Blau","rsbecker@nexbridge.com"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"500120","messageId":"95cdc30bad38f464b37e87d78f38e1d91c9e083b.1722886630.git.me@ttaylorr.com","threadId":"61903","inReplyTo":null,"subject":"[PATCH] t/t7704-repack-cruft.sh: avoid failures during long-running tests","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-08-05T19:37:11Z","receivedAt":"2024-08-05T19:37:14Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On systems where running t7704.09 takes longer than 10 seconds, the test\ncan fail.\n\nThe test works by doing the following:\n\n  - First write three unreachable objects, backdating the mtime for a\n    single object ($foo) which we expect to prune.\n\n  - Repack the repository into a pack containing reachable objects, and\n    another three cruft packs, each containing one of the objects\n    written in the previous step.\n\n  - Backdate the mtimes of the cruft pack *.mtimes files themselves.\n    (Note that this does not affect what is pruned further down in the\n    test, but is done to ensure that the cruft packs are rewritten\n    during that step).\n\n  - Then repack with --cruft-expiration=10.seconds.ago, expecting to\n    prune one of the three unreachable objects written in the first\n    step.\n\n  - Assert that the surviving cruft packs were rewritten, object $foo is\n    pruned, and unreachable objects $bar, and $baz remain in the\n    repository.\n\nIf longer than 10 seconds pass between writing the three unreachable\nobjects (the first step) and the \"git repack --cruft\" (the fourth step),\nwe will mistakenly prune more objects than expected, causing the test to\nfail.\n\nThe $foo object which we expect to prune has its mtime set back to\n10,000 seconds relative to the current time, but we prune it with a\ncutoff of 10.seconds.ago.\n\nInstead, set the cutoff to be 1,000 seconds to give the test much longer\ntime to run without failing. This helps platforms where running\nindividual tests can perform slowly, on my machine this test runs much\nmore quickly:\n\n    $ hyperfine './t7704-repack-cruft.sh --run=9'\n    Benchmark 1: ./t7704-repack-cruft.sh --run=9\n      Time (mean ± σ):     647.4 ms ±  30.7 ms    [User: 528.5 ms, System: 124.1 ms]\n      Range (min … max):   594.1 ms … 696.5 ms    10 runs\n\nReported-by: Randall Becker <randall.becker@nexbridge.com>\nSigned-off-by: Taylor Blau <me@ttaylorr.com>\n---\n t/t7704-repack-cruft.sh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/t/t7704-repack-cruft.sh b/t/t7704-repack-cruft.sh\nindex 71e1ef3a10..959e6e2648 100755\n--- a/t/t7704-repack-cruft.sh\n+++ b/t/t7704-repack-cruft.sh\n@@ -330,7 +330,7 @@ test_expect_success '--max-cruft-size with pruning' '\n \t\t# repack (and prune) with a --max-cruft-size to ensure\n \t\t# that we appropriately split the resulting set of packs\n \t\tgit repack -d --cruft --max-cruft-size=1M \\\n-\t\t\t--cruft-expiration=10.seconds.ago &&\n+\t\t\t--cruft-expiration=1000.seconds.ago &&\n \t\tls $packdir/pack-*.mtimes | sort >cruft.after &&\n \n \t\tfor cruft in $(cat cruft.after)\n\nbase-commit: 406f326d271e0bacecdb00425422c5fa3f314930\n-- \n2.46.0.46.g406f326d27.dirty\n"},{"id":"500124","messageId":"06b601dae774$2a9373a0$7fba5ae0$@nexbridge.com","threadId":"61903","inReplyTo":"95cdc30bad38f464b37e87d78f38e1d91c9e083b.1722886630.git.me@ttaylorr.com","subject":"RE: [PATCH] t/t7704-repack-cruft.sh: avoid failures during long-running tests","fromName":"","fromEmail":"rsbecker@nexbridge.com","sentAt":"2024-08-05T20:15:01Z","receivedAt":"2024-08-05T20:15:22Z","isPatch":true,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On Monday, August 5, 2024 3:37 PM, Taylor Blau wrote:\n>On systems where running t7704.09 takes longer than 10 seconds, the test can fail.\n>\n>The test works by doing the following:\n>\n>  - First write three unreachable objects, backdating the mtime for a\n>    single object ($foo) which we expect to prune.\n>\n>  - Repack the repository into a pack containing reachable objects, and\n>    another three cruft packs, each containing one of the objects\n>    written in the previous step.\n>\n>  - Backdate the mtimes of the cruft pack *.mtimes files themselves.\n>    (Note that this does not affect what is pruned further down in the\n>    test, but is done to ensure that the cruft packs are rewritten\n>    during that step).\n>\n>  - Then repack with --cruft-expiration=10.seconds.ago, expecting to\n>    prune one of the three unreachable objects written in the first\n>    step.\n>\n>  - Assert that the surviving cruft packs were rewritten, object $foo is\n>    pruned, and unreachable objects $bar, and $baz remain in the\n>    repository.\n>\n>If longer than 10 seconds pass between writing the three unreachable objects (the\n>first step) and the \"git repack --cruft\" (the fourth step), we will mistakenly prune\n>more objects than expected, causing the test to fail.\n>\n>The $foo object which we expect to prune has its mtime set back to\n>10,000 seconds relative to the current time, but we prune it with a cutoff of\n>10.seconds.ago.\n>\n>Instead, set the cutoff to be 1,000 seconds to give the test much longer time to run\n>without failing. This helps platforms where running individual tests can perform\n>slowly, on my machine this test runs much more quickly:\n>\n>    $ hyperfine './t7704-repack-cruft.sh --run=9'\n>    Benchmark 1: ./t7704-repack-cruft.sh --run=9\n>      Time (mean ± σ):     647.4 ms ±  30.7 ms    [User: 528.5 ms, System: 124.1 ms]\n>      Range (min … max):   594.1 ms … 696.5 ms    10 runs\n>\n>Reported-by: Randall Becker <randall.becker@nexbridge.com>\n>Signed-off-by: Taylor Blau <me@ttaylorr.com>\n>---\n> t/t7704-repack-cruft.sh | 2 +-\n> 1 file changed, 1 insertion(+), 1 deletion(-)\n>\n>diff --git a/t/t7704-repack-cruft.sh b/t/t7704-repack-cruft.sh index\n>71e1ef3a10..959e6e2648 100755\n>--- a/t/t7704-repack-cruft.sh\n>+++ b/t/t7704-repack-cruft.sh\n>@@ -330,7 +330,7 @@ test_expect_success '--max-cruft-size with pruning' '\n> \t\t# repack (and prune) with a --max-cruft-size to ensure\n> \t\t# that we appropriately split the resulting set of packs\n> \t\tgit repack -d --cruft --max-cruft-size=1M \\\n>-\t\t\t--cruft-expiration=10.seconds.ago &&\n>+\t\t\t--cruft-expiration=1000.seconds.ago &&\n> \t\tls $packdir/pack-*.mtimes | sort >cruft.after &&\n>\n> \t\tfor cruft in $(cat cruft.after)\n>\n>base-commit: 406f326d271e0bacecdb00425422c5fa3f314930\n>--\n>2.46.0.46.g406f326d27.dirty\n\nLGTM. Thank you.\n\n"}]}