| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "batch storage HTTP upload with tus protocol" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | # This repository name announces to the server that it should include |
| 10 | # "tus" in the set of transfer adapters it supports. |
| 11 | reponame="batch-storage-upload-tus" |
| 12 | setup_remote_repo "$reponame" |
| 13 | |
| 14 | clone_repo "$reponame" "$reponame" |
| 15 | git config lfs.tusTransfers true |
| 16 | |
| 17 | git lfs track "*.dat" |
| 18 | |
| 19 | # This content announces to the server that it should return a "verify" URL |
| 20 | # in its Batch API response, so the client can confirm that an upload |
| 21 | # was successful. Since we check for a successful upload using an |
| 22 | # assertion, this extra step is not strictly necessary. However, it helps |
| 23 | # demonstrate that "tus" protocol support works with the full Batch API. |
| 24 | contents_verify="send-verify-action" |
| 25 | contents_verify_oid="$(calc_oid "$contents_verify")" |
| 26 | |
| 27 | contents="test" |
| 28 | contents_oid=$(calc_oid "$contents") |
| 29 | |
| 30 | printf "%s" "$contents" > a.dat |
| 31 | printf "%s" "$contents_verify" > verify.dat |
| 32 | git add .gitattributes a.dat verify.dat |
| 33 | git commit -m "initial commit" |
| 34 | |
| 35 | GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log |
| 36 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 37 | echo >&2 "fatal: expected 'git lfs push' to succeed ..." |
| 38 | exit 1 |
| 39 | fi |
| 40 | |
| 41 | [ 2 -eq "$(grep -c "204 No Content" push.log)" ] |
| 42 | [ 4 -eq "$(grep -c "Upload-Offset: 0" push.log)" ] |
| 43 | [ 1 -eq "$(grep -c "Upload-Offset: ${#contents}$" push.log)" ] |
| 44 | [ 1 -eq "$(grep -c "Upload-Offset: ${#contents_verify}$" push.log)" ] |
| 45 | |
| 46 | [ 1 -eq "$(grep -c "xfer: tus.io uploading \"$contents_oid\" from start" push.log)" ] |
| 47 | [ 1 -eq "$(grep -c "xfer: tus.io uploading \"$contents_verify_oid\" from start" push.log)" ] |
| 48 | [ 1 -eq "$(grep -c "xfer: sending tus.io HEAD request for \"$contents_oid\"" push.log)" ] |
| 49 | [ 1 -eq "$(grep -c "xfer: sending tus.io HEAD request for \"$contents_verify_oid\"" push.log)" ] |
| 50 | [ 1 -eq "$(grep -c "xfer: sending tus.io PATCH request for \"$contents_oid\"" push.log)" ] |
| 51 | [ 1 -eq "$(grep -c "xfer: sending tus.io PATCH request for \"$contents_verify_oid\"" push.log)" ] |
| 52 | |
| 53 | [ 0 -eq "$(grep -c "xfer: tus.io resuming upload" push.log)" ] |
| 54 | |
| 55 | assert_server_object "$reponame" "$contents_oid" |
| 56 | assert_server_object "$reponame" "$contents_verify_oid" |
| 57 | ) |
| 58 | end_test |
| 59 | |
| 60 | begin_test "batch storage HTTP upload retries with tus protocol" |
| 61 | ( |
| 62 | set -e |
| 63 | |
| 64 | # This repository name announces to the server that it should include |
| 65 | # "tus" in the set of transfer adapters it supports, and that it should |
| 66 | # interrupt object uploads if they start from a zero byte offset, but |
| 67 | # otherwise allow them to complete. |
| 68 | reponame="batch-storage-upload-tus-interrupt" |
| 69 | setup_remote_repo "$reponame" |
| 70 | |
| 71 | clone_repo "$reponame" "$reponame" |
| 72 | git config lfs.tusTransfers true |
| 73 | |
| 74 | git lfs track "*.dat" |
| 75 | |
| 76 | # This content announces to the server that it should return a "verify" URL |
| 77 | # in its Batch API response, so the client can confirm that an upload |
| 78 | # was successful. Since we check for a successful upload using an |
| 79 | # assertion, this extra step is not strictly necessary. However, it helps |
| 80 | # demonstrate that "tus" protocol support works with the full Batch API. |
| 81 | contents_verify="send-verify-action" |
| 82 | contents_verify_oid="$(calc_oid "$contents_verify")" |
| 83 | |
| 84 | contents="test" |
| 85 | contents_oid=$(calc_oid "$contents") |
| 86 | |
| 87 | printf "%s" "$contents" > a.dat |
| 88 | printf "%s" "$contents_verify" > verify.dat |
| 89 | git add .gitattributes a.dat verify.dat |
| 90 | git commit -m "initial commit" |
| 91 | |
| 92 | GIT_TRACE=1 GIT_CURL_VERBOSE=1 git push origin main 2>&1 | tee push.log |
| 93 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 94 | echo >&2 "fatal: expected 'git lfs push' to succeed ..." |
| 95 | exit 1 |
| 96 | fi |
| 97 | |
| 98 | # The first attempts should start from a zero byte offset and be |
| 99 | # interrupted after exactly one third of the data is accepted. |
| 100 | [ 2 -eq "$(grep -c "500 Internal Server Error" push.log)" ] |
| 101 | [ 4 -eq "$(grep -c "Upload-Offset: 0" push.log)" ] |
| 102 | |
| 103 | # The second attempts should start from where the first attempts were |
| 104 | # interrupted, and should be successful. |
| 105 | [ 2 -eq "$(grep -c "204 No Content" push.log)" ] |
| 106 | [ 2 -eq "$(grep -c "Upload-Offset: $((${#contents} / 3))$" push.log)" ] |
| 107 | [ 2 -eq "$(grep -c "Upload-Offset: $((${#contents_verify} / 3))$" push.log)" ] |
| 108 | [ 1 -eq "$(grep -c "Upload-Offset: ${#contents}$" push.log)" ] |
| 109 | [ 1 -eq "$(grep -c "Upload-Offset: ${#contents_verify}$" push.log)" ] |
| 110 | |
| 111 | [ 1 -eq "$(grep -c "xfer: tus.io uploading \"$contents_oid\" from start" push.log)" ] |
| 112 | [ 1 -eq "$(grep -c "xfer: tus.io uploading \"$contents_verify_oid\" from start" push.log)" ] |
| 113 | [ 1 -eq "$(grep -c "xfer: tus.io resuming upload \"$contents_oid\" from $((${#contents} / 3))$" push.log)" ] |
| 114 | [ 1 -eq "$(grep -c "xfer: tus.io resuming upload \"$contents_verify_oid\" from $((${#contents_verify} / 3))$" push.log)" ] |
| 115 | [ 2 -eq "$(grep -c "xfer: sending tus.io HEAD request for \"$contents_oid\"" push.log)" ] |
| 116 | [ 2 -eq "$(grep -c "xfer: sending tus.io HEAD request for \"$contents_verify_oid\"" push.log)" ] |
| 117 | [ 2 -eq "$(grep -c "xfer: sending tus.io PATCH request for \"$contents_oid\"" push.log)" ] |
| 118 | [ 2 -eq "$(grep -c "xfer: sending tus.io PATCH request for \"$contents_verify_oid\"" push.log)" ] |
| 119 | |
| 120 | assert_server_object "$reponame" "$contents_oid" |
| 121 | assert_server_object "$reponame" "$contents_verify_oid" |
| 122 | ) |
| 123 | end_test |