File: t-resume-http-range.sh

package info (click to toggle)
git-lfs 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,808 kB
  • sloc: sh: 21,256; makefile: 507; ruby: 417
file content (128 lines) | stat: -rwxr-xr-x 3,816 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash

. "$(dirname "$0")/testlib.sh"

begin_test "resume-http-range"
(
  set -e

  reponame="$(basename "$0" ".sh")"
  setup_remote_repo "$reponame"

  clone_repo "$reponame" $reponame

  git lfs track "*.dat" 2>&1 | tee track.log
  grep "Tracking \"\*.dat\"" track.log

  # this string announces to server that we want a test that
  # interrupts the transfer when started from 0 to cause resume
  contents="status-batch-resume-206"
  contents_oid=$(calc_oid "$contents")

  printf "%s" "$contents" > a.dat
  git add a.dat
  git add .gitattributes
  git commit -m "add a.dat" 2>&1 | tee commit.log
  git push origin main

  assert_server_object "$reponame" "$contents_oid"

  # delete local copy then fetch it back
  # server will abort the transfer mid way (so will error) when not resuming
  # then we can restart it
  rm -rf .git/lfs/objects
  git lfs fetch 2>&1 | tee fetchinterrupted.log
  refute_local_object "$contents_oid"

  # now fetch again, this should try to resume and server should send remainder
  # this time (it does not cut short when Range is requested)
  GIT_TRACE=1 git lfs fetch 2>&1 | tee fetchresume.log
  grep "xfer: server accepted resume" fetchresume.log
  assert_local_object "$contents_oid" "${#contents}"

)
end_test

begin_test "resume-http-range-fallback"
(
  set -e

  reponame="resume-http-range-fallback"
  setup_remote_repo "$reponame"

  clone_repo "$reponame" $reponame

  git lfs track "*.dat" 2>&1 | tee track.log
  grep "Tracking \"\*.dat\"" track.log

  # this string announces to server that we want it to abort the download part
  # way, but reject the Range: header and fall back on re-downloading instead
  contents="batch-resume-fail-fallback"
  contents_oid=$(calc_oid "$contents")

  printf "%s" "$contents" > a.dat
  git add a.dat
  git add .gitattributes
  git commit -m "add a.dat" 2>&1 | tee commit.log
  git push origin main

  assert_server_object "$reponame" "$contents_oid"

  # delete local copy then fetch it back
  # server will abort the transfer mid way (so will error) when not resuming
  # then we can restart it
  rm -rf .git/lfs/objects
  git lfs fetch 2>&1 | tee fetchinterrupted.log
  refute_local_object "$contents_oid"

  # now fetch again, this should try to resume but server should reject the Range
  # header, which should cause client to re-download
  GIT_TRACE=1 git lfs fetch 2>&1 | tee fetchresumefallback.log
  grep "xfer: server rejected resume" fetchresumefallback.log
  # re-download should still have worked
  assert_local_object "$contents_oid" "${#contents}"

)
end_test

begin_test "resume-http-range-retry"
(
  set -e

  reponame="resume-http-range-retry"
  setup_remote_repo "$reponame"

  clone_repo "$reponame" $reponame

  git lfs track "*.dat" 2>&1 | tee track.log
  grep "Tracking \"\*.dat\"" track.log

  # This string announces to server that we want a test that strictly handles
  # Range headers, rejecting any where the latter part of the range is smaller
  # than the former part.
  contents="status-batch-retry"
  contents_oid=$(calc_oid "$contents")

  printf "%s" "$contents" > a.dat
  git add a.dat
  git add .gitattributes
  git commit -m "add a.dat" 2>&1 | tee commit.log
  git push origin main

  assert_server_object "$reponame" "$contents_oid"

  # Delete local copy then fetch it back.
  rm -rf .git/lfs/objects
  refute_local_object "$contents_oid"

  # Create a partial corrupt object.
  mkdir .git/lfs/incomplete
  printf "%s" "${contents/st/aa}" >".git/lfs/incomplete/$contents_oid.tmp"

  # The first download may fail with an error; run a second time to make sure
  # that we detect the corrupt file and retry.
  GIT_TRACE=1 git lfs fetch 2>&1 | tee fetchresume.log
  GIT_TRACE=1 git lfs fetch 2>&1 | tee fetchresume.log
  assert_local_object "$contents_oid" "${#contents}"
)
end_test