Skip to content

Commit 7bc73e7

Browse files
derrickstoleegitster
authored andcommitted
t5558: add tests for creationToken heuristic
As documented in the bundle URI design doc in 2da14fa (docs: document bundle URI standard, 2022-08-09), the 'creationToken' member of a bundle URI allows a bundle provider to specify a total order on the bundles. Future changes will allow the Git client to understand these members and modify its behavior around downloading the bundles in that order. In the meantime, create tests that add creation tokens to the bundle list. For now, the Git client correctly ignores these unknown keys. Create a new test helper function, test_remote_https_urls, which filters GIT_TRACE2_EVENT output to extract a list of URLs passed to git-remote-https child processes. This can be used to verify the order of these requests as we implement the creationToken heuristic. For now, we need to sort the actual output since the current client does not have a well-defined order that it applies to the bundles. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d9fd674 commit 7bc73e7

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

t/t5558-clone-bundle-uri.sh

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ test_expect_success 'clone HTTP bundle' '
285285
'
286286

287287
test_expect_success 'clone bundle list (HTTP, no heuristic)' '
288+
test_when_finished rm -f trace*.txt &&
289+
288290
cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
289291
cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
290292
[bundle]
@@ -304,12 +306,26 @@ test_expect_success 'clone bundle list (HTTP, no heuristic)' '
304306
uri = $HTTPD_URL/bundle-4.bundle
305307
EOF
306308
307-
git clone --bundle-uri="$HTTPD_URL/bundle-list" \
309+
GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" \
310+
git clone --bundle-uri="$HTTPD_URL/bundle-list" \
308311
clone-from clone-list-http 2>err &&
309312
! grep "Repository lacks these prerequisite commits" err &&
310313
311314
git -C clone-from for-each-ref --format="%(objectname)" >oids &&
312-
git -C clone-list-http cat-file --batch-check <oids
315+
git -C clone-list-http cat-file --batch-check <oids &&
316+
317+
cat >expect <<-EOF &&
318+
$HTTPD_URL/bundle-1.bundle
319+
$HTTPD_URL/bundle-2.bundle
320+
$HTTPD_URL/bundle-3.bundle
321+
$HTTPD_URL/bundle-4.bundle
322+
$HTTPD_URL/bundle-list
323+
EOF
324+
325+
# Sort the list, since the order is not well-defined
326+
# without a heuristic.
327+
test_remote_https_urls <trace-clone.txt | sort >actual &&
328+
test_cmp expect actual
313329
'
314330

315331
test_expect_success 'clone bundle list (HTTP, any mode)' '
@@ -350,6 +366,55 @@ test_expect_success 'clone bundle list (HTTP, any mode)' '
350366
test_cmp expect actual
351367
'
352368

369+
test_expect_success 'clone bundle list (http, creationToken)' '
370+
test_when_finished rm -f trace*.txt &&
371+
372+
cp clone-from/bundle-*.bundle "$HTTPD_DOCUMENT_ROOT_PATH/" &&
373+
cat >"$HTTPD_DOCUMENT_ROOT_PATH/bundle-list" <<-EOF &&
374+
[bundle]
375+
version = 1
376+
mode = all
377+
heuristic = creationToken
378+
379+
[bundle "bundle-1"]
380+
uri = bundle-1.bundle
381+
creationToken = 1
382+
383+
[bundle "bundle-2"]
384+
uri = bundle-2.bundle
385+
creationToken = 2
386+
387+
[bundle "bundle-3"]
388+
uri = bundle-3.bundle
389+
creationToken = 3
390+
391+
[bundle "bundle-4"]
392+
uri = bundle-4.bundle
393+
creationToken = 4
394+
EOF
395+
396+
GIT_TRACE2_EVENT="$(pwd)/trace-clone.txt" git \
397+
clone --bundle-uri="$HTTPD_URL/bundle-list" \
398+
"$HTTPD_URL/smart/fetch.git" clone-list-http-2 &&
399+
400+
git -C clone-from for-each-ref --format="%(objectname)" >oids &&
401+
git -C clone-list-http-2 cat-file --batch-check <oids &&
402+
403+
cat >expect <<-EOF &&
404+
$HTTPD_URL/bundle-1.bundle
405+
$HTTPD_URL/bundle-2.bundle
406+
$HTTPD_URL/bundle-3.bundle
407+
$HTTPD_URL/bundle-4.bundle
408+
$HTTPD_URL/bundle-list
409+
EOF
410+
411+
# Since the creationToken heuristic is not yet understood by the
412+
# client, the order cannot be verified at this moment. Sort the
413+
# list for consistent results.
414+
test_remote_https_urls <trace-clone.txt | sort >actual &&
415+
test_cmp expect actual
416+
'
417+
353418
# Do not add tests here unless they use the HTTP server, as they will
354419
# not run unless the HTTP dependencies exist.
355420

t/test-lib-functions.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,14 @@ test_region () {
18331833
return 0
18341834
}
18351835

1836+
# Given a GIT_TRACE2_EVENT log over stdin, writes to stdout a list of URLs
1837+
# sent to git-remote-https child processes.
1838+
test_remote_https_urls() {
1839+
grep -e '"event":"child_start".*"argv":\["git-remote-https",".*"\]' |
1840+
sed -e 's/{"event":"child_start".*"argv":\["git-remote-https","//g' \
1841+
-e 's/"\]}//g'
1842+
}
1843+
18361844
# Print the destination of symlink(s) provided as arguments. Basically
18371845
# the same as the readlink command, but it's not available everywhere.
18381846
test_readlink () {

0 commit comments

Comments
 (0)