| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "batch API HTTP upload causes delayed retries" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="upload-batch-retry-later" |
| 10 | setup_remote_repo "$reponame" |
| 11 | clone_repo "$reponame" batch-repo-upload |
| 12 | |
| 13 | contents="content" |
| 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_TRACE=1 git push origin main 2>&1 | tee push.log |
| 22 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 23 | echo >&2 "fatal: expected \`git push origin main\` to succeed ..." |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
| 27 | [ 1 -eq $(grep -c "tq: enqueue retry" push.log) ] |
| 28 | |
| 29 | assert_server_object "$reponame" "$oid" |
| 30 | ) |
| 31 | end_test |
| 32 | |
| 33 | begin_test "batch API HTTP upload with multiple files causes delayed retries" |
| 34 | ( |
| 35 | set -e |
| 36 | |
| 37 | reponame="upload-multiple-batch-retry-later" |
| 38 | setup_remote_repo "$reponame" |
| 39 | clone_repo "$reponame" batch-repo-upload-multiple |
| 40 | |
| 41 | contents1="content 1" |
| 42 | oid1="$(calc_oid "$contents1")" |
| 43 | printf "%s" "$contents1" > a.dat |
| 44 | |
| 45 | contents2="content 2" |
| 46 | oid2="$(calc_oid "$contents2")" |
| 47 | printf "%s" "$contents2" > b.dat |
| 48 | |
| 49 | git lfs track "*.dat" |
| 50 | git add .gitattributes a.dat b.dat |
| 51 | git commit -m "initial commit" |
| 52 | |
| 53 | GIT_TRACE=1 git push origin main 2>&1 | tee push.log |
| 54 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 55 | echo >&2 "fatal: expected \`git push origin main\` to succeed ..." |
| 56 | exit 1 |
| 57 | fi |
| 58 | |
| 59 | [ 2 -eq $(grep -c "tq: enqueue retry" push.log) ] |
| 60 | [ 2 -eq $(grep -c "tq: enqueue retry #1" push.log) ] |
| 61 | |
| 62 | assert_server_object "$reponame" "$oid1" |
| 63 | assert_server_object "$reponame" "$oid2" |
| 64 | ) |
| 65 | end_test |
| 66 | |
| 67 | begin_test "batch API HTTP download causes delayed retries" |
| 68 | ( |
| 69 | set -e |
| 70 | |
| 71 | reponame="clone-batch-retry-later" |
| 72 | setup_remote_repo "$reponame" |
| 73 | clone_repo "$reponame" batch-repo-clone |
| 74 | |
| 75 | contents="content" |
| 76 | oid="$(calc_oid "$contents")" |
| 77 | printf "%s" "$contents" > a.dat |
| 78 | |
| 79 | git lfs track "*.dat" |
| 80 | git add .gitattributes a.dat |
| 81 | git commit -m "initial commit" |
| 82 | |
| 83 | # Note that the server would apply the default rate limit delay only |
| 84 | # to this push operation, not the subsequent clone whose handling of |
| 85 | # 429 responses we want to test. To avoid this, we first set the |
| 86 | # available non-rate-limited requests for the repository to the maximum |
| 87 | # allowed, which allows the push to proceed without delay. Then we |
| 88 | # reset the available requests to zero afterwards so the clone will |
| 89 | # receive a 429 response. |
| 90 | set_server_rate_limit "batch" "" "$reponame" "" "max" |
| 91 | |
| 92 | git push origin main |
| 93 | assert_server_object "$reponame" "$oid" |
| 94 | |
| 95 | set_server_rate_limit "batch" "" "$reponame" "" 0 |
| 96 | |
| 97 | pushd .. |
| 98 | GIT_TRACE=1 git lfs clone "$GITSERVER/$reponame" "$reponame-assert" 2>&1 | tee clone.log |
| 99 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 100 | echo >&2 "fatal: expected \`git lfs clone \"$GITSERVER/$reponame\" \"$reponame-assert\"\` to succeed ..." |
| 101 | exit 1 |
| 102 | fi |
| 103 | |
| 104 | [ 1 -eq $(grep -c "tq: enqueue retry" clone.log) ] |
| 105 | |
| 106 | cd "$reponame-assert" |
| 107 | |
| 108 | assert_local_object "$oid" "${#contents}" |
| 109 | popd |
| 110 | ) |
| 111 | end_test |
| 112 | |
| 113 | begin_test "batch API HTTP download with multiple files causes delayed retries" |
| 114 | ( |
| 115 | set -e |
| 116 | |
| 117 | reponame="clone-multiple-batch-retry-later" |
| 118 | setup_remote_repo "$reponame" |
| 119 | clone_repo "$reponame" batch-repo-clone-multiple |
| 120 | |
| 121 | contents1="content 1" |
| 122 | oid1="$(calc_oid "$contents1")" |
| 123 | printf "%s" "$contents1" > a.dat |
| 124 | |
| 125 | contents2="content 2" |
| 126 | oid2="$(calc_oid "$contents2")" |
| 127 | printf "%s" "$contents2" > b.dat |
| 128 | |
| 129 | git lfs track "*.dat" |
| 130 | git add .gitattributes a.dat b.dat |
| 131 | git commit -m "initial commit" |
| 132 | |
| 133 | # Note that the server would apply the default rate limit delay only |
| 134 | # to this push operation, not the subsequent clone whose handling of |
| 135 | # 429 responses we want to test. To avoid this, we first set the |
| 136 | # available non-rate-limited requests for the repository to the maximum |
| 137 | # allowed, which allows the push to proceed without delay. Then we |
| 138 | # reset the available requests to zero afterwards so the clone will |
| 139 | # receive a 429 response. |
| 140 | set_server_rate_limit "batch" "" "$reponame" "" "max" |
| 141 | |
| 142 | git push origin main |
| 143 | assert_server_object "$reponame" "$oid1" |
| 144 | assert_server_object "$reponame" "$oid2" |
| 145 | |
| 146 | set_server_rate_limit "batch" "" "$reponame" "" 0 |
| 147 | |
| 148 | pushd .. |
| 149 | GIT_TRACE=1 git lfs clone "$GITSERVER/$reponame" "$reponame-assert" 2>&1 | tee clone.log |
| 150 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 151 | echo >&2 "fatal: expected \`git lfs clone \"$GITSERVER/$reponame\" \"$reponame-assert\"\` to succeed ..." |
| 152 | exit 1 |
| 153 | fi |
| 154 | |
| 155 | [ 2 -eq $(grep -c "tq: enqueue retry" clone.log) ] |
| 156 | [ 2 -eq $(grep -c "tq: enqueue retry #1" clone.log) ] |
| 157 | |
| 158 | cd "$reponame-assert" |
| 159 | |
| 160 | assert_local_object "$oid1" "${#contents1}" |
| 161 | assert_local_object "$oid2" "${#contents2}" |
| 162 | popd |
| 163 | ) |
| 164 | end_test |
| 165 | |
| 166 | begin_test "batch API HTTP upload causes retries (missing header)" |
| 167 | ( |
| 168 | set -e |
| 169 | |
| 170 | reponame="upload-batch-retry-later-no-header" |
| 171 | setup_remote_repo "$reponame" |
| 172 | clone_repo "$reponame" batch-repo-upload-no-header |
| 173 | |
| 174 | contents="content" |
| 175 | oid="$(calc_oid "$contents")" |
| 176 | printf "%s" "$contents" > a.dat |
| 177 | |
| 178 | git lfs track "*.dat" |
| 179 | git add .gitattributes a.dat |
| 180 | git commit -m "initial commit" |
| 181 | |
| 182 | GIT_TRACE=1 git push origin main 2>&1 | tee push.log |
| 183 | if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 184 | echo >&2 "fatal: expected \`git push origin main\` to succeed ..." |
| 185 | exit 1 |
| 186 | fi |
| 187 | |
| 188 | [ 1 -lt $(grep -c "tq: enqueue retry" push.log) ] |
| 189 | [ 1 -eq $(grep -c "tq: enqueue retry #1" push.log) ] |
| 190 | [ 1 -eq $(grep -c "tq: enqueue retry #2" push.log) ] |
| 191 | |
| 192 | assert_server_object "$reponame" "$oid" |
| 193 | ) |
| 194 | end_test |
| 195 | |
| 196 | begin_test "batch API HTTP upload fails when Retry-After exceeds maxRetryTime" |
| 197 | ( |
| 198 | set -e |
| 199 | |
| 200 | # This repository name announces to the server that it should |
| 201 | # respond to all Batch API requests with a 429 Too Many Requests |
| 202 | # status code and a Retry-After header until at least 10 seconds |
| 203 | # have passed after the first request to the Batch API. |
| 204 | reponame="upload-batch-retry-later-exceeds-max" |
| 205 | setup_remote_repo "$reponame" |
| 206 | clone_repo "$reponame" "$reponame" |
| 207 | |
| 208 | git config lfs.transfer.maxRetryTime 5 |
| 209 | |
| 210 | contents="content" |
| 211 | oid="$(calc_oid "$contents")" |
| 212 | printf "%s" "$contents" > a.dat |
| 213 | |
| 214 | git lfs track "*.dat" |
| 215 | git add .gitattributes a.dat |
| 216 | git commit -m "initial commit" |
| 217 | |
| 218 | GIT_TRACE=1 git push origin main 2>&1 | tee push.log |
| 219 | [ 0 -ne "${PIPESTATUS[0]}" ] |
| 220 | |
| 221 | grep -E "tq: refusing to retry \"$oid\", retry after [0-9]+s exceeds maximum 5s" push.log |
| 222 | |
| 223 | refute_server_object "$reponame" "$oid" |
| 224 | ) |
| 225 | end_test |