@matheusbsbs / matheus-bagliano / commits / 713c79e84b
Fork 0

more war on "sleep" in tests

Two more tests that sleep only to waste tick can be converted to use test_tick and take expiry parameters relative to $test_tick. The basic idea is to replace "sleep 1" with "test_tick" to cause the "time" to pass. These tests are interested in expiring things with "now" as the timestamp, soo use a timestamp relative to $test_tick to give them more stability and reproducibility. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Apr 14, 2010 at 15:09 UTC 713c79e84bb148b8166d866755d155f64b270ac9
2 files changed +15 -7
t/t7700-repack.sh
+6 -3
@@ -8,6 +8,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
8 echo content1 > file1 &&
9 echo content2 > file2 &&
10 git add . &&
11 + test_tick &&
12 git commit -m initial_commit &&
13 # Create two packs
14 # The first pack will contain all of the objects except one
@@ -40,6 +41,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
41 echo content3 > file3 &&
42 objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
43 git add file3 &&
44 + test_tick &&
45 git commit -m commit_file3 &&
46 git repack -a -d -l &&
47 git prune-packed &&
@@ -73,6 +75,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack
75 rm -f .git/objects/pack/* &&
76 echo new_content >> file1 &&
77 git add file1 &&
78 + test_tick &&
79 git commit -m more_content &&
80 git repack &&
81 git repack -a -d &&
@@ -118,8 +121,8 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
121 mv .git/objects/pack/* alt_objects/pack/ &&
122 csha1=$(git rev-parse HEAD^{commit}) &&
123 git reset --hard HEAD^ &&
121 - sleep 1 &&
122 - git reflog expire --expire=now --expire-unreachable=now --all &&
124 + test_tick &&
125 + git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
126 # The pack-objects call on the next line is equivalent to
127 # git repack -A -d without the call to prune-packed
128 git pack-objects --honor-pack-keep --non-empty --all --reflog \
@@ -156,7 +159,7 @@ test_expect_success 'objects made unreachable by grafts only are kept' '
159 H1=$(git rev-parse HEAD^) &&
160 H2=$(git rev-parse HEAD^^) &&
161 echo "$H0 $H2" > .git/info/grafts &&
159 - git reflog expire --expire=now --expire-unreachable=now --all &&
162 + git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
163 git repack -a -d &&
164 git cat-file -t $H1
165 '
t/t7701-repack-unpack-unreachable.sh
+9 -4
@@ -11,17 +11,20 @@ tsha1=
11 test_expect_success '-A with -d option leaves unreachable objects unpacked' '
12 echo content > file1 &&
13 git add . &&
14 + test_tick &&
15 git commit -m initial_commit &&
16 # create a transient branch with unique content
17 git checkout -b transient_branch &&
18 echo more content >> file1 &&
19 # record the objects created in the database for file, commit, tree
20 fsha1=$(git hash-object file1) &&
21 + test_tick &&
22 git commit -a -m more_content &&
23 csha1=$(git rev-parse HEAD^{commit}) &&
24 tsha1=$(git rev-parse HEAD^{tree}) &&
25 git checkout master &&
26 echo even more content >> file1 &&
27 + test_tick &&
28 git commit -a -m even_more_content &&
29 # delete the transient branch
30 git branch -D transient_branch &&
@@ -34,9 +37,11 @@ test_expect_success '-A with -d option leaves unreachable objects unpacked' '
37 git show $fsha1 &&
38 git show $csha1 &&
39 git show $tsha1 &&
37 - # now expire the reflog
38 - sleep 1 &&
39 - git reflog expire --expire-unreachable=now --all &&
40 + # now expire the reflog, while keeping reachable ones but expiring
41 + # unreachables immediately
42 + test_tick &&
43 + sometimeago=$(( $test_tick - 10000 )) &&
44 + git reflog expire --expire=$sometimeago --expire-unreachable=$test_tick --all &&
45 # and repack
46 git repack -A -d -l &&
47 # verify objects are retained unpacked
@@ -71,7 +76,7 @@ test_expect_success '-A without -d option leaves unreachable objects packed' '
76 test 1 = $(ls -1 .git/objects/pack/pack-*.pack | wc -l) &&
77 packfile=$(ls .git/objects/pack/pack-*.pack) &&
78 git branch -D transient_branch &&
74 - sleep 1 &&
79 + test_tick &&
80 git repack -A -l &&
81 test ! -f "$fsha1path" &&
82 test ! -f "$csha1path" &&