The eleventh batch
[alt-git.git] / t / t1701-racy-split-index.sh
blobd8fa489998acc5984da7e21a8a2adf43cfe88cee
1 #!/bin/sh
3 # This test can give false success if your machine is sufficiently
4 # slow or all trials happened to happen on second boundaries.
6 test_description='racy split index'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success 'setup' '
12 # Only split the index when the test explicitly says so.
13 sane_unset GIT_TEST_SPLIT_INDEX &&
14 git config splitIndex.maxPercentChange 100 &&
16 echo "cached content" >racy-file &&
17 git add racy-file &&
18 git commit -m initial &&
20 echo something >other-file &&
21 # No raciness with this file.
22 test-tool chmtime =-20 other-file &&
24 echo "+cached content" >expect
27 check_cached_diff () {
28 git diff-index --patch --cached $EMPTY_TREE racy-file >diff &&
29 tail -1 diff >actual &&
30 test_cmp expect actual
33 trials="0 1 2 3 4"
34 for trial in $trials
36 test_expect_success "split the index while adding a racily clean file #$trial" '
37 rm -f .git/index .git/sharedindex.* &&
39 # The next three commands must be run within the same
40 # second (so both writes to racy-file result in the same
41 # mtime) to create the interesting racy situation.
42 echo "cached content" >racy-file &&
44 # Update and split the index. The cache entry of
45 # racy-file will be stored only in the shared index.
46 git update-index --split-index --add racy-file &&
48 # File size must stay the same.
49 echo "dirty worktree" >racy-file &&
51 # Subsequent git commands should notice that racy-file
52 # and the split index have the same mtime, and check
53 # the content of the file to see if it is actually
54 # clean.
55 check_cached_diff
57 done
59 for trial in $trials
61 test_expect_success "add a racily clean file to an already split index #$trial" '
62 rm -f .git/index .git/sharedindex.* &&
64 git update-index --split-index &&
66 # The next three commands must be run within the same
67 # second.
68 echo "cached content" >racy-file &&
70 # Update the split index. The cache entry of racy-file
71 # will be stored only in the split index.
72 git update-index --add racy-file &&
74 # File size must stay the same.
75 echo "dirty worktree" >racy-file &&
77 # Subsequent git commands should notice that racy-file
78 # and the split index have the same mtime, and check
79 # the content of the file to see if it is actually
80 # clean.
81 check_cached_diff
83 done
85 for trial in $trials
87 test_expect_success "split the index when the index contains a racily clean cache entry #$trial" '
88 rm -f .git/index .git/sharedindex.* &&
90 # The next three commands must be run within the same
91 # second.
92 echo "cached content" >racy-file &&
94 git update-index --add racy-file &&
96 # File size must stay the same.
97 echo "dirty worktree" >racy-file &&
99 # Now wait a bit to ensure that the split index written
100 # below will get a more recent mtime than racy-file.
101 sleep 1 &&
103 # Update and split the index when the index contains
104 # the racily clean cache entry of racy-file.
105 # A corresponding replacement cache entry with smudged
106 # stat data should be added to the new split index.
107 git update-index --split-index --add other-file &&
109 # Subsequent git commands should notice the smudged
110 # stat data in the replacement cache entry and that it
111 # doesnt match with the file the worktree.
112 check_cached_diff
114 done
116 for trial in $trials
118 test_expect_success "update the split index when it contains a new racily clean cache entry #$trial" '
119 rm -f .git/index .git/sharedindex.* &&
121 git update-index --split-index &&
123 # The next three commands must be run within the same
124 # second.
125 echo "cached content" >racy-file &&
127 # Update the split index. The cache entry of racy-file
128 # will be stored only in the split index.
129 git update-index --add racy-file &&
131 # File size must stay the same.
132 echo "dirty worktree" >racy-file &&
134 # Now wait a bit to ensure that the split index written
135 # below will get a more recent mtime than racy-file.
136 sleep 1 &&
138 # Update the split index when the racily clean cache
139 # entry of racy-file is only stored in the split index.
140 # An updated cache entry with smudged stat data should
141 # be added to the new split index.
142 git update-index --add other-file &&
144 # Subsequent git commands should notice the smudged
145 # stat data.
146 check_cached_diff
148 done
150 for trial in $trials
152 test_expect_success "update the split index when a racily clean cache entry is stored only in the shared index #$trial" '
153 rm -f .git/index .git/sharedindex.* &&
155 # The next three commands must be run within the same
156 # second.
157 echo "cached content" >racy-file &&
159 # Update and split the index. The cache entry of
160 # racy-file will be stored only in the shared index.
161 git update-index --split-index --add racy-file &&
163 # File size must stay the same.
164 echo "dirty worktree" >racy-file &&
166 # Now wait a bit to ensure that the split index written
167 # below will get a more recent mtime than racy-file.
168 sleep 1 &&
170 # Update the split index when the racily clean cache
171 # entry of racy-file is only stored in the shared index.
172 # A corresponding replacement cache entry with smudged
173 # stat data should be added to the new split index.
174 git update-index --add other-file &&
176 # Subsequent git commands should notice the smudged
177 # stat data.
178 check_cached_diff
180 done
182 for trial in $trials
184 test_expect_success "update the split index after unpack trees() copied a racily clean cache entry from the shared index #$trial" '
185 rm -f .git/index .git/sharedindex.* &&
187 # The next three commands must be run within the same
188 # second.
189 echo "cached content" >racy-file &&
191 # Update and split the index. The cache entry of
192 # racy-file will be stored only in the shared index.
193 git update-index --split-index --add racy-file &&
195 # File size must stay the same.
196 echo "dirty worktree" >racy-file &&
198 # Now wait a bit to ensure that the split index written
199 # below will get a more recent mtime than racy-file.
200 sleep 1 &&
202 # Update the split index after unpack_trees() copied the
203 # racily clean cache entry of racy-file from the shared
204 # index. A corresponding replacement cache entry
205 # with smudged stat data should be added to the new
206 # split index.
207 git read-tree -m HEAD &&
209 # Subsequent git commands should notice the smudged
210 # stat data.
211 check_cached_diff
213 done
215 test_done