Debian Codegraph @

t/t-batch-storage-retries.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 . "$(dirnamescip-shell system . . 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 printfscip-shell system . . printf. "%s" "$contents" > a.dat
16
17 gitscip-shell system . . git. lfs track "*.dat"
18 gitscip-shell system . . git. add .gitattributes a.dat
19 gitscip-shell system . . git. commit -m "initial commit"
20
21 gitscip-shell system . . git. config --local lfs.transfer.maxretries 3
22
23 GIT_TRACE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
24 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
25 echoscip-shell system . . echo. >&2 "fatal: expected \`git push origin main\` to succeed ..."
26 exit 1
27 fi
28
29 actual_count="$(grepscip-shell system . . grep. -c "tq: retrying object $oid: Fatal error: Server error" push.log)"
30 [scip-shell system . . `[`. "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 printfscip-shell system . . printf. "%s" "$contents" > a.dat
47
48 gitscip-shell system . . git. lfs track "*.dat"
49 gitscip-shell system . . git. add .gitattributes a.dat
50 gitscip-shell system . . git. commit -m "initial commit"
51
52 gitscip-shell system . . git. push origin main
53 assert_server_object "$reponame" "$oid"
54
55 pushd ..
56 gitscip-shell system . . 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 gitscip-shell system . . git. config credential.helper lfstest
65 gitscip-shell system . . git. config --local lfs.transfer.maxretries 3
66
67 GIT_TRACE=1 gitscip-shell system . . git. lfs pull origin main 2>&1 | teescip-shell system . . tee. pull.log
68 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
69 echoscip-shell system . . echo. >&2 "fatal: expected \`git lfs pull origin main\` to succeed ..."
70 exit 1
71 fi
72
73 actual_count="$(grepscip-shell system . . grep. -c "tq: retrying object $oid: Fatal error: Server error" pull.log)"
74 [scip-shell system . . `[`. "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 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
91 grepscip-shell system . . 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 printfscip-shell system . . printf. "%s" "$contents" > a.dat
100 gitscip-shell system . . git. add a.dat
101 gitscip-shell system . . git. add .gitattributes
102 gitscip-shell system . . git. commit -m "add a.dat"
103 gitscip-shell system . . 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 rmscip-shell system . . rm. -rf .git/lfs/objects
111
112 GIT_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. lfs fetch 2>&1 | teescip-shell system . . tee. fetch.log
113 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
114 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs fetch' to succeed ..."
115 exit 1
116 fi
117
118 grepscip-shell system . . grep. "Attempting to resume download of \"$contents_oid\"" fetch.log
119 grepscip-shell system . . grep. "tq: retrying object $contents_oid" fetch.log
120 grepscip-shell system . . grep. "Range: bytes=$((${#contents} / 2))-$((${#contents} - 1))" fetch.log
121
122 grepscip-shell system . . grep. "206 Partial Content" fetch.log
123 grepscip-shell system . . grep. "Content-Range: bytes $((${#contents} / 2))-$((${#contents} - 1))/${#contents}" fetch.log
124 grepscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
141 grepscip-shell system . . 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 printfscip-shell system . . printf. "%s" "$contents" > a.dat
150 gitscip-shell system . . git. add a.dat
151 gitscip-shell system . . git. add .gitattributes
152 gitscip-shell system . . git. commit -m "add a.dat"
153 gitscip-shell system . . 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 rmscip-shell system . . rm. -rf .git/lfs/objects
162
163 GIT_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. lfs fetch 2>&1 | teescip-shell system . . tee. fetch.log
164 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
165 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs fetch' to succeed ..."
166 exit 1
167 fi
168
169 grepscip-shell system . . grep. "Attempting to resume download of \"$contents_oid\"" fetch.log
170 grepscip-shell system . . grep. "tq: retrying object $contents_oid" fetch.log
171 grepscip-shell system . . grep. "Range: bytes=$((${#contents} / 2))-$((${#contents} - 1))" fetch.log
172
173 grepscip-shell system . . grep. "416 Requested Range Not Satisfiable" fetch.log
174 grepscip-shell system . . 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 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
190 grepscip-shell system . . 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 printfscip-shell system . . printf. "%s" "$contents" > a.dat
199 gitscip-shell system . . git. add a.dat
200 gitscip-shell system . . git. add .gitattributes
201 gitscip-shell system . . git. commit -m "add a.dat"
202 gitscip-shell system . . 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 rmscip-shell system . . rm. -rf .git/lfs/objects
228
229 # Create a corrupt partial download file smaller than the actual object.
230 mkdirscip-shell system . . mkdir. -p .git/lfs/incomplete
231 printfscip-shell system . . printf. "%s" "aa" >".git/lfs/incomplete/$contents_oid.part"
232
233 GIT_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. lfs fetch 2>&1 | teescip-shell system . . tee. fetch.log
234 if [scip-shell system . . `[`. "0" -eq "${PIPESTATUS[0]}" ]; then
235 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs fetch' to fail ..."
236 exit 1
237 fi
238
239 grepscip-shell system . . grep. "Attempting to resume download of \"$contents_oid\"" fetch.log
240 grepscip-shell system . . grep. "Range: bytes=2-$((${#contents} - 1))" fetch.log
241
242 grepscip-shell system . . grep. "206 Partial Content" fetch.log
243 grepscip-shell system . . grep. "Content-Range: bytes 2-$((${#contents} - 1))/${#contents}" fetch.log
244 grepscip-shell system . . grep. "xfer: server accepted resume .*$contents_oid" fetch.log
245
246 grepscip-shell system . . grep. "expected OID $contents_oid, got" fetch.log
247 grepscip-shell system . . 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 printfscip-shell system . . printf. "%s" "${contents/st/aa}" >".git/lfs/incomplete/$contents_oid.part"
253
254 GIT_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. lfs fetch 2>&1 | teescip-shell system . . tee. fetch.log
255 if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then
256 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs fetch' to succeed ..."
257 exit 1
258 fi
259
260 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "Attempting to resume download of \"$contents_oid\"" fetch.log)" ]
261 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "tq: retrying object $contents_oid" fetch.log)" ]
262 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "Range: bytes=" fetch.log)" ]
263 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "400 Bad Request" fetch.log)" ]
264
265 assert_local_object "$contents_oid" "${#contents}"
266 )
267 end_test