Debian Codegraph @

t/t-batch-storage-retries.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . "$(dirname "$0")/testlib.sh"
4
5 begin_test "batch storage HTTP upload causes retries"
6 (
7 set -e
8
9 reponame="batch-storage-upload-retry"
10 setup_remote_repo "$reponame"
11 clone_repo "$reponame" batch-storage-repo-upload
12
13 contents="storage-upload-retry"
14 oid="$(calc_oid "$contents")"
15 printf "%s" "$contents" > a.dat
16
17 git lfs track "*.dat"
18 git add .gitattributes a.dat
19 git commit -m "initial commit"
20
21 git config --local lfs.transfer.maxretries 3
22
23 GIT_TRACE=1 git push origin main 2>&1 | tee push.log
24 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
25 echo >&2 "fatal: expected \`git push origin main\` to succeed ..."
26 exit 1
27 fi
28
29 actual_count="$(grep -c "tq: retrying object $oid: Fatal error: Server error" push.log)"
30 [ "2" = "$actual_count" ]
31
32 assert_server_object "$reponame" "$oid"
33 )
34 end_test
35
36 begin_test "batch storage HTTP download causes retries"
37 (
38 set -e
39
40 reponame="batch-storage-download-retry"
41 setup_remote_repo "$reponame"
42 clone_repo "$reponame" batch-storage-repo-download
43
44 contents="storage-download-retry"
45 oid="$(calc_oid "$contents")"
46 printf "%s" "$contents" > a.dat
47
48 git lfs track "*.dat"
49 git add .gitattributes a.dat
50 git commit -m "initial commit"
51
52 git push origin main
53 assert_server_object "$reponame" "$oid"
54
55 pushd ..
56 git \
57 -c "filter.lfs.process=" \
58 -c "filter.lfs.smudge=cat" \
59 -c "filter.lfs.required=false" \
60 clone "$GITSERVER/$reponame" "$reponame-assert"
61
62 cd "$reponame-assert"
63
64 git config credential.helper lfstest
65 git config --local lfs.transfer.maxretries 3
66
67 GIT_TRACE=1 git lfs pull origin main 2>&1 | tee pull.log
68 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
69 echo >&2 "fatal: expected \`git lfs pull origin main\` to succeed ..."
70 exit 1
71 fi
72
73 actual_count="$(grep -c "tq: retrying object $oid: Fatal error: Server error" pull.log)"
74 [ "2" = "$actual_count" ]
75
76 assert_local_object "$oid" "${#contents}"
77 popd
78 )
79 end_test
80
81 begin_test "batch storage HTTP download retries with Range header"
82 (
83 set -e
84
85 reponame="batch-storage-download-retry-range"
86 setup_remote_repo "$reponame"
87
88 clone_repo "$reponame" "$reponame"
89
90 git lfs track "*.dat" 2>&1 | tee track.log
91 grep "Tracking \"\*.dat\"" track.log
92
93 # This content announces to the server that it should interrupt the
94 # object download halfway, unless a Range header with a positive offset
95 # was sent.
96 contents="storage-download-retry-range"
97 contents_oid=$(calc_oid "$contents")
98
99 printf "%s" "$contents" > a.dat
100 git add a.dat
101 git add .gitattributes
102 git commit -m "add a.dat"
103 git push origin main
104
105 assert_server_object "$reponame" "$contents_oid"
106
107 # Test object transfer download with an interrupted initial response,
108 # after which the client should fetch the remaining bytes using a request
109 # with a Range header.
110 rm -rf .git/lfs/objects
111
112 GIT_TRACE=1 GIT_CURL_VERBOSE=1 git lfs fetch 2>&1 | tee fetch.log
113 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
114 echo >&2 "fatal: expected 'git lfs fetch' to succeed ..."
115 exit 1
116 fi
117
118 grep "Attempting to resume download of \"$contents_oid\"" fetch.log
119 grep "tq: retrying object $contents_oid" fetch.log
120 grep "Range: bytes=$((${#contents} / 2))-$((${#contents} - 1))" fetch.log
121
122 grep "206 Partial Content" fetch.log
123 grep "Content-Range: bytes $((${#contents} / 2))-$((${#contents} - 1))/${#contents}" fetch.log
124 grep "xfer: server accepted resume .*$contents_oid" fetch.log
125
126 assert_local_object "$contents_oid" "${#contents}"
127
128 )
129 end_test
130
131 begin_test "batch storage HTTP download retries after Range header rejected"
132 (
133 set -e
134
135 reponame="batch-storage-download-retry-range-rejected"
136 setup_remote_repo "$reponame"
137
138 clone_repo "$reponame" "$reponame"
139
140 git lfs track "*.dat" 2>&1 | tee track.log
141 grep "Tracking \"\*.dat\"" track.log
142
143 # This content announces to the server that it should interrupt the first
144 # object download halfway, then reject the client's Range header request,
145 # forcing the client to fall back on re-downloading instead.
146 contents="storage-download-retry-range-rejected"
147 contents_oid=$(calc_oid "$contents")
148
149 printf "%s" "$contents" > a.dat
150 git add a.dat
151 git add .gitattributes
152 git commit -m "add a.dat"
153 git push origin main
154
155 assert_server_object "$reponame" "$contents_oid"
156
157 # Test object transfer download with an interrupted initial response,
158 # after which the client should attempt to fetch the remaining bytes using
159 # a request with a Range header. When the server rejects that request,
160 # the client should then re-request the entire object.
161 rm -rf .git/lfs/objects
162
163 GIT_TRACE=1 GIT_CURL_VERBOSE=1 git lfs fetch 2>&1 | tee fetch.log
164 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
165 echo >&2 "fatal: expected 'git lfs fetch' to succeed ..."
166 exit 1
167 fi
168
169 grep "Attempting to resume download of \"$contents_oid\"" fetch.log
170 grep "tq: retrying object $contents_oid" fetch.log
171 grep "Range: bytes=$((${#contents} / 2))-$((${#contents} - 1))" fetch.log
172
173 grep "416 Requested Range Not Satisfiable" fetch.log
174 grep "xfer: server rejected resume .*$contents_oid.* re-downloading from start" fetch.log
175
176 assert_local_object "$contents_oid" "${#contents}"
177 )
178 end_test
179
180 begin_test "batch storage HTTP download retries without invalid Range header"
181 (
182 set -e
183
184 reponame="batch-storage-download-retry-no-invalid-range"
185 setup_remote_repo "$reponame"
186
187 clone_repo "$reponame" "$reponame"
188
189 git lfs track "*.dat" 2>&1 | tee track.log
190 grep "Tracking \"\*.dat\"" track.log
191
192 # This content announces to the server that it should strictly validate
193 # Range headers, rejecting any where the ending index of the byte range is
194 # smaller than the starting index.
195 contents="storage-download-retry-no-invalid-range"
196 contents_oid=$(calc_oid "$contents")
197
198 printf "%s" "$contents" > a.dat
199 git add a.dat
200 git add .gitattributes
201 git commit -m "add a.dat"
202 git push origin main
203
204 assert_server_object "$reponame" "$contents_oid"
205
206 # Test object transfer download by simulating an interrupted and corrupt
207 # initial response, after which the client should fetch the remaining bytes
208 # using a request with a Range header, then detect that the assembled
209 # object data is invalid and report an error.
210 #
211 # Next, test object transfer download again by simulating a complete but
212 # corrupt initial response, after which the client should detect that
213 # the object data is invalid and re-request the entire object.
214 #
215 # Note that the principal purpose of the first check is simply to verify
216 # that the client reads the simulated temporary download files this test
217 # creates. If the client's handling of these files changes in the future,
218 # this portion of the test should fail, alerting us to the need to
219 # rewrite this test.
220 #
221 # The purpose of the second check is to verify that the client does not
222 # send invalid Range headers when a temporary download file equals or
223 # exceeds the size of the corresponding object. Since this results in
224 # single normal object transfer download, the test would trivially pass
225 # even if the temporary file was simulated incorrectly, so the preceding
226 # check exists to ensure we are simulating these files correctly.
227 rm -rf .git/lfs/objects
228
229 # Create a corrupt partial download file smaller than the actual object.
230 mkdir -p .git/lfs/incomplete
231 printf "%s" "aa" >".git/lfs/incomplete/$contents_oid.part"
232
233 GIT_TRACE=1 GIT_CURL_VERBOSE=1 git lfs fetch 2>&1 | tee fetch.log
234 if [ "0" -eq "${PIPESTATUS[0]}" ]; then
235 echo >&2 "fatal: expected 'git lfs fetch' to fail ..."
236 exit 1
237 fi
238
239 grep "Attempting to resume download of \"$contents_oid\"" fetch.log
240 grep "Range: bytes=2-$((${#contents} - 1))" fetch.log
241
242 grep "206 Partial Content" fetch.log
243 grep "Content-Range: bytes 2-$((${#contents} - 1))/${#contents}" fetch.log
244 grep "xfer: server accepted resume .*$contents_oid" fetch.log
245
246 grep "expected OID $contents_oid, got" fetch.log
247 grep "error: failed to fetch some objects" fetch.log
248
249 refute_local_object "$contents_oid"
250
251 # Create a corrupt partial download file equal in size to the actual object.
252 printf "%s" "${contents/st/aa}" >".git/lfs/incomplete/$contents_oid.part"
253
254 GIT_TRACE=1 GIT_CURL_VERBOSE=1 git lfs fetch 2>&1 | tee fetch.log
255 if [ "0" -ne "${PIPESTATUS[0]}" ]; then
256 echo >&2 "fatal: expected 'git lfs fetch' to succeed ..."
257 exit 1
258 fi
259
260 [ 0 -eq "$(grep -c "Attempting to resume download of \"$contents_oid\"" fetch.log)" ]
261 [ 0 -eq "$(grep -c "tq: retrying object $contents_oid" fetch.log)" ]
262 [ 0 -eq "$(grep -c "Range: bytes=" fetch.log)" ]
263 [ 0 -eq "$(grep -c "400 Bad Request" fetch.log)" ]
264
265 assert_local_object "$contents_oid" "${#contents}"
266 )
267 end_test