t / t5552-skipping-fetch-negotiator.shon commit cat-file: support "unordered" output for --batch-all-objects (0750bb5)
   1#!/bin/sh
   2
   3test_description='test skipping fetch negotiator'
   4. ./test-lib.sh
   5
   6have_sent () {
   7        while test "$#" -ne 0
   8        do
   9                grep "fetch> have $(git -C client rev-parse $1)" trace
  10                if test $? -ne 0
  11                then
  12                        echo "No have $(git -C client rev-parse $1) ($1)"
  13                        return 1
  14                fi
  15                shift
  16        done
  17}
  18
  19have_not_sent () {
  20        while test "$#" -ne 0
  21        do
  22                grep "fetch> have $(git -C client rev-parse $1)" trace
  23                if test $? -eq 0
  24                then
  25                        return 1
  26                fi
  27                shift
  28        done
  29}
  30
  31test_expect_success 'commits with no parents are sent regardless of skip distance' '
  32        git init server &&
  33        test_commit -C server to_fetch &&
  34
  35        git init client &&
  36        for i in $(seq 7)
  37        do
  38                test_commit -C client c$i
  39        done &&
  40
  41        # We send: "c7" (skip 1) "c5" (skip 2) "c2" (skip 4). After that, since
  42        # "c1" has no parent, it is still sent as "have" even though it would
  43        # normally be skipped.
  44        test_config -C client fetch.negotiationalgorithm skipping &&
  45        GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
  46        have_sent c7 c5 c2 c1 &&
  47        have_not_sent c6 c4 c3
  48'
  49
  50test_expect_success 'when two skips collide, favor the larger one' '
  51        rm -rf server client trace &&
  52        git init server &&
  53        test_commit -C server to_fetch &&
  54
  55        git init client &&
  56        for i in $(seq 11)
  57        do
  58                test_commit -C client c$i
  59        done &&
  60        git -C client checkout c5 &&
  61        test_commit -C client c5side &&
  62
  63        # Before reaching c5, we send "c5side" (skip 1) and "c11" (skip 1) "c9"
  64        # (skip 2) "c6" (skip 4). The larger skip (skip 4) takes precedence, so
  65        # the next "have" sent will be "c1" (from "c6" skip 4) and not "c4"
  66        # (from "c5side" skip 1).
  67        test_config -C client fetch.negotiationalgorithm skipping &&
  68        GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
  69        have_sent c5side c11 c9 c6 c1 &&
  70        have_not_sent c10 c8 c7 c5 c4 c3 c2
  71'
  72
  73test_expect_success 'use ref advertisement to filter out commits' '
  74        rm -rf server client trace &&
  75        git init server &&
  76        test_commit -C server c1 &&
  77        test_commit -C server c2 &&
  78        test_commit -C server c3 &&
  79        git -C server tag -d c1 c2 c3 &&
  80
  81        git clone server client &&
  82        test_commit -C client c4 &&
  83        test_commit -C client c5 &&
  84        git -C client checkout c4^^ &&
  85        test_commit -C client c2side &&
  86
  87        git -C server checkout --orphan anotherbranch &&
  88        test_commit -C server to_fetch &&
  89
  90        # The server advertising "c3" (as "refs/heads/master") means that we do
  91        # not need to send any ancestors of "c3", but we still need to send "c3"
  92        # itself.
  93        test_config -C client fetch.negotiationalgorithm skipping &&
  94        GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch origin to_fetch &&
  95        have_sent c5 c4^ c2side &&
  96        have_not_sent c4 c4^^ c4^^^
  97'
  98
  99test_expect_success 'handle clock skew' '
 100        rm -rf server client trace &&
 101        git init server &&
 102        test_commit -C server to_fetch &&
 103
 104        git init client &&
 105
 106        # 2 regular commits
 107        test_tick=2000000000 &&
 108        test_commit -C client c1 &&
 109        test_commit -C client c2 &&
 110
 111        # 4 old commits
 112        test_tick=1000000000 &&
 113        git -C client checkout c1 &&
 114        test_commit -C client old1 &&
 115        test_commit -C client old2 &&
 116        test_commit -C client old3 &&
 117        test_commit -C client old4 &&
 118
 119        # "c2" and "c1" are popped first, then "old4" to "old1". "old1" would
 120        # normally be skipped, but is treated as a commit without a parent here
 121        # and sent, because (due to clock skew) its only parent has already been
 122        # popped off the priority queue.
 123        test_config -C client fetch.negotiationalgorithm skipping &&
 124        GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" &&
 125        have_sent c2 c1 old4 old2 old1 &&
 126        have_not_sent old3
 127'
 128
 129test_expect_success 'do not send "have" with ancestors of commits that server ACKed' '
 130        rm -rf server client trace &&
 131        git init server &&
 132        test_commit -C server to_fetch &&
 133
 134        git init client &&
 135        for i in $(seq 8)
 136        do
 137                git -C client checkout --orphan b$i &&
 138                test_commit -C client b$i.c0
 139        done &&
 140        for j in $(seq 19)
 141        do
 142                for i in $(seq 8)
 143                do
 144                        git -C client checkout b$i &&
 145                        test_commit -C client b$i.c$j
 146                done
 147        done &&
 148
 149        # Copy this branch over to the server and add a commit on it so that it
 150        # is reachable but not advertised.
 151        git -C server fetch --no-tags "$(pwd)/client" b1:refs/heads/b1 &&
 152        git -C server checkout b1 &&
 153        test_commit -C server commit-on-b1 &&
 154
 155        test_config -C client fetch.negotiationalgorithm skipping &&
 156        GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "$(pwd)/server" to_fetch &&
 157        grep "  fetch" trace &&
 158
 159        # fetch-pack sends 2 requests each containing 16 "have" lines before
 160        # processing the first response. In these 2 requests, 4 commits from
 161        # each branch are sent. Just check the first branch.
 162        have_sent b1.c19 b1.c17 b1.c14 b1.c9 &&
 163        have_not_sent b1.c18 b1.c16 b1.c15 b1.c13 b1.c12 b1.c11 b1.c10 &&
 164
 165        # While fetch-pack is processing the first response, it should read that
 166        # the server ACKs b1.c19 and b1.c17.
 167        grep "fetch< ACK $(git -C client rev-parse b1.c19) common" trace &&
 168        grep "fetch< ACK $(git -C client rev-parse b1.c17) common" trace &&
 169
 170        # fetch-pack should thus not send any more commits in the b1 branch, but
 171        # should still send the others (in this test, just check b2).
 172        for i in $(seq 0 8)
 173        do
 174                have_not_sent b1.c$i
 175        done &&
 176        have_sent b2.c1 b2.c0
 177'
 178
 179test_done