| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "batch storage HTTP download with gzip encoding" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="batch-storage-download-encoding-gzip" |
| 10 | setup_remote_repo "$reponame" |
| 11 | clone_repo "$reponame" "$reponame" |
| 12 | |
| 13 | git lfs track "*.dat" |
| 14 | |
| 15 | # This content announces to the server that it should expect an |
| 16 | # "Accept-Encoding: gzip" header and send a gzip-compressed response. |
| 17 | contents="storage-download-encoding-gzip" |
| 18 | contents_oid=$(calc_oid "$contents") |
| 19 | printf "%s" "$contents" >a.dat |
| 20 | |
| 21 | git add .gitattributes a.dat |
| 22 | git commit -m "initial commit" |
| 23 | |
| 24 | git push origin main |
| 25 | |
| 26 | # Test object transfer download with an "Accept-Encoding: gzip" header |
| 27 | # that should be generated automatically without explicit configuration. |
| 28 | rm -rf .git/lfs/objects |
| 29 | |
| 30 | GIT_TRACE=1 GIT_CURL_VERBOSE=1 git lfs pull 2>&1 | tee pull.log |
| 31 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 32 | echo >&2 "fatal: expected 'git lfs pull' to succeed ..." |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
| 36 | # We expect one "Accept-Encoding: gzip" header from the Batch API request, |
| 37 | # prior to the object transfer download request. |
| 38 | [ 2 -eq "$(grep -c "Accept-Encoding: gzip" pull.log)" ] |
| 39 | |
| 40 | [ 1 -eq "$(grep -c "decompressed gzipped response" pull.log)" ] |
| 41 | |
| 42 | assert_local_object "$contents_oid" "${#contents}" |
| 43 | |
| 44 | # Test again with an explicit configuration. |
| 45 | rm -rf .git/lfs/objects |
| 46 | |
| 47 | git config lfs.transfer.httpDownloadEncoding gzip |
| 48 | |
| 49 | GIT_TRACE=1 GIT_CURL_VERBOSE=1 git lfs pull 2>&1 | tee pull.log |
| 50 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 51 | echo >&2 "fatal: expected 'git lfs pull' to succeed ..." |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
| 55 | # We expect one "Accept-Encoding: gzip" header from the Batch API request, |
| 56 | # prior to the object transfer download request. |
| 57 | [ 2 -eq "$(grep -c "Accept-Encoding: gzip" pull.log)" ] |
| 58 | |
| 59 | [ 1 -eq "$(grep -c "decompressed gzipped response" pull.log)" ] |
| 60 | |
| 61 | assert_local_object "$contents_oid" "${#contents}" |
| 62 | |
| 63 | # Test again with a URL-specific configuration. |
| 64 | rm -rf .git/lfs/objects |
| 65 | |
| 66 | git config --unset lfs.transfer.httpDownloadEncoding |
| 67 | git config "lfs.transfer.$GITSERVER.httpDownloadEncoding" gzip |
| 68 | |
| 69 | GIT_TRACE=1 GIT_CURL_VERBOSE=1 git lfs pull 2>&1 | tee pull.log |
| 70 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 71 | echo >&2 "fatal: expected 'git lfs pull' to succeed ..." |
| 72 | exit 1 |
| 73 | fi |
| 74 | |
| 75 | # We expect one "Accept-Encoding: gzip" header from the Batch API request, |
| 76 | # prior to the object transfer download request. |
| 77 | [ 2 -eq "$(grep -c "Accept-Encoding: gzip" pull.log)" ] |
| 78 | |
| 79 | [ 1 -eq "$(grep -c "decompressed gzipped response" pull.log)" ] |
| 80 | |
| 81 | assert_local_object "$contents_oid" "${#contents}" |
| 82 | ) |
| 83 | end_test |
| 84 | |
| 85 | begin_test "batch storage HTTP download with zstd encoding" |
| 86 | ( |
| 87 | set -e |
| 88 | |
| 89 | reponame="batch-storage-download-encoding-zstd" |
| 90 | setup_remote_repo "$reponame" |
| 91 | clone_repo "$reponame" "$reponame" |
| 92 | |
| 93 | git lfs track "*.dat" |
| 94 | |
| 95 | # This content announces to the server that it should expect an |
| 96 | # "Accept-Encoding: zstd" header and send a zstd-compressed response. |
| 97 | contents="storage-download-encoding-zstd" |
| 98 | contents_oid=$(calc_oid "$contents") |
| 99 | printf "%s" "$contents" >a.dat |
| 100 | |
| 101 | git add .gitattributes a.dat |
| 102 | git commit -m "initial commit" |
| 103 | |
| 104 | git push origin main |
| 105 | |
| 106 | # Test object transfer download with an "Accept-Encoding: zstd" header. |
| 107 | rm -rf .git/lfs/objects |
| 108 | |
| 109 | git config lfs.transfer.httpDownloadEncoding zstd |
| 110 | |
| 111 | GIT_TRACE=1 GIT_CURL_VERBOSE=1 git lfs pull 2>&1 | tee pull.log |
| 112 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 113 | echo >&2 "fatal: expected 'git lfs pull' to succeed ..." |
| 114 | exit 1 |
| 115 | fi |
| 116 | |
| 117 | # We expect one "Accept-Encoding: gzip" header from the Batch API request, |
| 118 | # prior to the object transfer download request. |
| 119 | [ 1 -eq "$(grep -c "Accept-Encoding: gzip" pull.log)" ] |
| 120 | [ 1 -eq "$(grep -c "Accept-Encoding: zstd" pull.log)" ] |
| 121 | |
| 122 | [ 1 -eq "$(grep -c "Content-Encoding: zstd" pull.log)" ] |
| 123 | [ 1 -eq "$(grep -c "decompressing zstd-encoded response" pull.log)" ] |
| 124 | |
| 125 | assert_local_object "$contents_oid" "${#contents}" |
| 126 | |
| 127 | # Test again with a URL-specific configuration. |
| 128 | rm -rf .git/lfs/objects |
| 129 | |
| 130 | git config --unset lfs.transfer.httpDownloadEncoding |
| 131 | git config "lfs.transfer.$GITSERVER.httpDownloadEncoding" zstd |
| 132 | |
| 133 | GIT_TRACE=1 GIT_CURL_VERBOSE=1 git lfs pull 2>&1 | tee pull.log |
| 134 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 135 | echo >&2 "fatal: expected 'git lfs pull' to succeed ..." |
| 136 | exit 1 |
| 137 | fi |
| 138 | |
| 139 | # We expect one "Accept-Encoding: gzip" header from the Batch API request, |
| 140 | # prior to the object transfer download request. |
| 141 | [ 1 -eq "$(grep -c "Accept-Encoding: gzip" pull.log)" ] |
| 142 | [ 1 -eq "$(grep -c "Accept-Encoding: zstd" pull.log)" ] |
| 143 | |
| 144 | [ 1 -eq "$(grep -c "Content-Encoding: zstd" pull.log)" ] |
| 145 | [ 1 -eq "$(grep -c "decompressing zstd-encoded response" pull.log)" ] |
| 146 | |
| 147 | assert_local_object "$contents_oid" "${#contents}" |
| 148 | ) |
| 149 | end_test |
| 150 | |
| 151 | begin_test "batch storage HTTP download with zstd encoding and multiple objects" |
| 152 | ( |
| 153 | set -e |
| 154 | |
| 155 | reponame="batch-storage-download-encoding-zstd-multiple" |
| 156 | setup_remote_repo "$reponame" |
| 157 | clone_repo "$reponame" "$reponame" |
| 158 | |
| 159 | git lfs track "*.dat" |
| 160 | |
| 161 | # This content announces to the server that it should expect an |
| 162 | # "Accept-Encoding: zstd" header and send a zstd-compressed response. |
| 163 | contents1="storage-download-encoding-zstd-1" |
| 164 | contents2="storage-download-encoding-zstd-2" |
| 165 | contents3="storage-download-encoding-zstd-3" |
| 166 | contents1_oid=$(calc_oid "$contents1") |
| 167 | contents2_oid=$(calc_oid "$contents2") |
| 168 | contents3_oid=$(calc_oid "$contents3") |
| 169 | printf "%s" "$contents1" >test1.dat |
| 170 | printf "%s" "$contents2" >test2.dat |
| 171 | printf "%s" "$contents3" >test3.dat |
| 172 | |
| 173 | git add .gitattributes test*.dat |
| 174 | git commit -m "initial commit" |
| 175 | |
| 176 | git push origin main |
| 177 | |
| 178 | # Test object transfer download with an "Accept-Encoding: zstd" header. |
| 179 | rm -rf .git/lfs/objects |
| 180 | |
| 181 | git config lfs.transfer.httpDownloadEncoding zstd |
| 182 | |
| 183 | # Allow no more than two concurrent transfer workers, each with a |
| 184 | # dedicated zstd decoder. |
| 185 | git config lfs.concurrentTransfers 2 |
| 186 | |
| 187 | GIT_TRACE=1 GIT_CURL_VERBOSE=1 git lfs pull 2>&1 | tee pull.log |
| 188 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 189 | echo >&2 "fatal: expected 'git lfs pull' to succeed ..." |
| 190 | exit 1 |
| 191 | fi |
| 192 | |
| 193 | # We expect one "Accept-Encoding: gzip" header from the Batch API request, |
| 194 | # prior to the object transfer download requests. |
| 195 | [ 1 -eq "$(grep -c "Accept-Encoding: gzip" pull.log)" ] |
| 196 | [ 3 -eq "$(grep -c "Accept-Encoding: zstd" pull.log)" ] |
| 197 | |
| 198 | [ 3 -eq "$(grep -c "Content-Encoding: zstd" pull.log)" ] |
| 199 | [ 3 -eq "$(grep -c "decompressing zstd-encoded response" pull.log)" ] |
| 200 | |
| 201 | # We expect one zstd decoder to be initialized for each transfer worker. |
| 202 | [ 2 -eq "$(grep -c "initialized zstd decoder" pull.log)" ] |
| 203 | [ 2 -eq "$(grep -c "closed zstd decoder" pull.log)" ] |
| 204 | |
| 205 | assert_local_object "$contents1_oid" "${#contents1}" |
| 206 | assert_local_object "$contents2_oid" "${#contents2}" |
| 207 | assert_local_object "$contents3_oid" "${#contents3}" |
| 208 | ) |
| 209 | end_test |
| 210 | |
| 211 | begin_test "batch storage HTTP download with zstd encoding retries with Range header and without encoding" |
| 212 | ( |
| 213 | set -e |
| 214 | |
| 215 | reponame="batch-storage-download-encoding-zstd-retry-range" |
| 216 | setup_remote_repo "$reponame" |
| 217 | clone_repo "$reponame" "$reponame" |
| 218 | |
| 219 | git lfs track "*.dat" |
| 220 | |
| 221 | # This content announces to the server that it should expect an |
| 222 | # "Accept-Encoding: zstd" header and send a zstd-encoded response |
| 223 | # unless a Range header with a positive offset was sent. As well, |
| 224 | # the server should interrupt the initial response after at least one |
| 225 | # complete zstd-encoded frame has been delivered. |
| 226 | contents="storage-download-encoding-zstd-retry-range" |
| 227 | contents_oid=$(calc_oid "$contents") |
| 228 | printf "%s" "$contents" >a.dat |
| 229 | |
| 230 | git add .gitattributes a.dat |
| 231 | git commit -m "initial commit" |
| 232 | |
| 233 | git push origin main |
| 234 | |
| 235 | # Test object transfer download with an "Accept-Encoding: zstd" header |
| 236 | # and an interrupted initial response, after which the client should |
| 237 | # fetch the remaining bytes using a request with a Range header and |
| 238 | # without an "Accept-Encoding: zstd" header. |
| 239 | rm -rf .git/lfs/objects |
| 240 | |
| 241 | git config lfs.transfer.httpDownloadEncoding zstd |
| 242 | |
| 243 | GIT_TRACE=1 GIT_CURL_VERBOSE=1 git lfs fetch 2>&1 | tee fetch.log |
| 244 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 245 | echo >&2 "fatal: expected 'git lfs fetch' to succeed ..." |
| 246 | exit 1 |
| 247 | fi |
| 248 | |
| 249 | # We expect one "Accept-Encoding: gzip" header from the Batch API request |
| 250 | # prior to each object transfer download request. We expect one object |
| 251 | # transfer download request with an "Accept-Encoding: zstd" header, then a |
| 252 | # retried request with a Range header but without a Accept-Encoding header. |
| 253 | [ 2 -eq "$(grep -c "Accept-Encoding: gzip" fetch.log)" ] |
| 254 | [ 1 -eq "$(grep -c "Accept-Encoding: zstd" fetch.log)" ] |
| 255 | |
| 256 | [ 1 -eq "$(grep -c "Content-Encoding: zstd" fetch.log)" ] |
| 257 | [ 1 -eq "$(grep -c "decompressing zstd-encoded response" fetch.log)" ] |
| 258 | |
| 259 | # The server should encode the object data in two frames of equal length and |
| 260 | # interrupt the first download response after the first frame, so we expect |
| 261 | # the next download attempt to request just the second half of the data. |
| 262 | grep "Attempting to resume download of \"$contents_oid\"" fetch.log |
| 263 | grep "tq: retrying object $contents_oid" fetch.log |
| 264 | grep "Range: bytes=$((${#contents} / 2))-$((${#contents} - 1))" fetch.log |
| 265 | |
| 266 | grep "206 Partial Content" fetch.log |
| 267 | grep "Content-Range: bytes $((${#contents} / 2))-$((${#contents} - 1))/${#contents}" fetch.log |
| 268 | grep "xfer: server accepted resume .*$contents_oid" fetch.log |
| 269 | |
| 270 | assert_local_object "$contents_oid" "${#contents}" |
| 271 | ) |
| 272 | end_test |
| 273 | |
| 274 | begin_test "batch storage HTTP download with invalid encoding" |
| 275 | ( |
| 276 | set -e |
| 277 | |
| 278 | reponame="batch-storage-download-encoding-invalid" |
| 279 | setup_remote_repo "$reponame" |
| 280 | clone_repo "$reponame" "$reponame" |
| 281 | |
| 282 | git lfs track "*.dat" |
| 283 | printf "contents" > a.dat |
| 284 | git add .gitattributes a.dat |
| 285 | git commit -m "initial commit" |
| 286 | |
| 287 | git push origin main |
| 288 | |
| 289 | # Now test download with invalid Accept-Encoding value |
| 290 | rm -rf .git/lfs/objects |
| 291 | |
| 292 | git config lfs.transfer.httpDownloadEncoding "br" |
| 293 | |
| 294 | # Should fail with an error |
| 295 | git lfs pull 2>&1 | tee pull.log |
| 296 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 297 | echo >&2 "fatal: expected 'git lfs pull' to fail ..." |
| 298 | exit 1 |
| 299 | fi |
| 300 | |
| 301 | grep "unsupported lfs\.transfer\.httpDownloadEncoding" pull.log |
| 302 | ) |
| 303 | end_test |
| 304 | |
| 305 | begin_test "batch storage HTTP upload with chunked transfer encoding" |
| 306 | ( |
| 307 | set -e |
| 308 | |
| 309 | # This repository name announces to the server that it should |
| 310 | # include in the "header" JSON element of its Batch API responses |
| 311 | # a "Transfer-Encoding" key with the value "chunked", and that the |
| 312 | # server should expect a corresponding HTTP header during object uploads. |
| 313 | reponame="batch-storage-upload-encoding-chunked" |
| 314 | setup_remote_repo "$reponame" |
| 315 | clone_repo "$reponame" "$reponame" |
| 316 | |
| 317 | git lfs track "*.dat" |
| 318 | |
| 319 | contents="storage-upload-encoding-chunked" |
| 320 | contents_oid=$(calc_oid "$contents") |
| 321 | printf "%s" "$contents" >a.dat |
| 322 | |
| 323 | git add .gitattributes a.dat |
| 324 | git commit -m "initial commit" |
| 325 | |
| 326 | GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log |
| 327 | [ 0 -eq "${PIPESTATUS[0]}" ] |
| 328 | |
| 329 | # To confirm that when the object was uploaded, the PUT request included a |
| 330 | # Transfer-Encoding header and did not include a Content-Length header, |
| 331 | # we filter out the initial portion of the trace log with the headers |
| 332 | # from the Batch and Locking API requests. |
| 333 | prog="$(printf 'index($0, " PUT %s/storage/") > 0 { f=1 } f' "$GITSERVER")" |
| 334 | awk "$prog" push.log >put.log |
| 335 | |
| 336 | grep "> Transfer-Encoding: chunked" put.log |
| 337 | [ 0 -eq "$(grep -c -i "> Content-Length:" put.log)" ] |
| 338 | |
| 339 | assert_server_object "$reponame" "$contents_oid" |
| 340 | ) |
| 341 | end_test |
| 342 | |
| 343 | begin_test "batch storage HTTP upload without transfer encoding" |
| 344 | ( |
| 345 | set -e |
| 346 | |
| 347 | reponame="batch-storage-upload-encoding-none" |
| 348 | setup_remote_repo "$reponame" |
| 349 | clone_repo "$reponame" "$reponame" |
| 350 | |
| 351 | git lfs track "*.dat" |
| 352 | |
| 353 | contents="storage-upload-encoding-none" |
| 354 | contents_oid=$(calc_oid "$contents") |
| 355 | printf "%s" "$contents" >a.dat |
| 356 | |
| 357 | git add .gitattributes a.dat |
| 358 | git commit -m "initial commit" |
| 359 | |
| 360 | GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log |
| 361 | [ 0 -eq "${PIPESTATUS[0]}" ] |
| 362 | |
| 363 | # To confirm that when the object was uploaded, the PUT request included a |
| 364 | # Content-Length header and did not include a Transfer-Encoding header, |
| 365 | # we filter out the initial portion of the trace log with the headers |
| 366 | # from the Batch and Locking API requests. |
| 367 | prog="$(printf 'index($0, " PUT %s/storage/") > 0 { f=1 } f' "$GITSERVER")" |
| 368 | awk "$prog" push.log >put.log |
| 369 | |
| 370 | grep "> Content-Length: ${#contents}$" put.log |
| 371 | [ 0 -eq "$(grep -c -i "> Transfer-Encoding:" put.log)" ] |
| 372 | |
| 373 | assert_server_object "$reponame" "$contents_oid" |
| 374 | ) |
| 375 | end_test |