summaryrefslogtreecommitdiff
path: root/test/integration/test-acquire-same-repository-multiple-times
blob: eea81fd69e34b94752bf386ae978e271211d2264 (plain)
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
#!/bin/sh
set -e

TESTDIR=$(readlink -f $(dirname $0))
. $TESTDIR/framework
setupenvironment
configarchitecture 'amd64'

TESTFILE="$TESTDIR/framework"
cp $TESTFILE aptarchive/foo
APTARCHIVE="$(readlink -f ./aptarchive)"

getcodenamefromsuite() { echo "jessie"; }
buildsimplenativepackage 'foo' 'all' '1.0' 'stable'
setupaptarchive --no-update
ln -s "${APTARCHIVE}/dists/stable" "${APTARCHIVE}/dists/jessie"
for FILE in rootdir/etc/apt/sources.list.d/*-stable-* ; do
	sed 's#stable#jessie#g' $FILE > $(echo "$FILE" | sed 's#stable#jessie#g')
done

# install a slowed down file: otherwise its to fast to reproduce combining
NEWMETHODS="$(readlink -f rootdir)/usr/lib/apt/methods"
OLDMETHODS="$(readlink -f rootdir/usr/lib/apt/methods)"
rm "$NEWMETHODS"
mkdir "$NEWMETHODS"
backupIFS="$IFS"
IFS="$(printf "\n\b")"
for METH in $(find "$OLDMETHODS" ! -type d); do
	ln -s "$OLDMETHODS/$(basename "$METH")" "$NEWMETHODS"
done
IFS="$backupIFS"
rm "${NEWMETHODS}/file" "${NEWMETHODS}/http"
cat >"${NEWMETHODS}/file" <<EOF
#!/bin/sh
while read line; do
	echo "\$line"
	if [ -z "\$line" ]; then
		sleep 0.5
	fi
done | "$OLDMETHODS/\${0##*/}"
EOF
chmod +x "${NEWMETHODS}/file"
ln -s "${NEWMETHODS}/file" "${NEWMETHODS}/http"

tworepos() {
	msgtest "Downloading the same repository twice over $1" "$3"
	testsuccess --nomsg aptget update -o Debug::pkgAcquire::Worker=1
	cp rootdir/tmp/testsuccess.output download.log
	#cat download.log
	aptget indextargets --format '$(FILENAME)' --no-release-info | sort > file.lst
	testequal "$(find "$(readlink -f ./rootdir/var/lib/apt/lists)" -name '*_dists_*' \( ! -name '*InRelease' \) -type f | sort)" cat file.lst
	testsuccess aptcache policy
	testequal "foo:
  Installed: (none)
  Candidate: 1.0
  Version table:
     1.0 500
        500 $1:$2 jessie/main all Packages
        500 $1:$2 stable/main all Packages" aptcache policy foo
	testfailure aptcache show foo/unstable
	testsuccess aptcache show foo/stable
	testsuccess aptcache show foo/jessie
}

tworepos 'file' "$APTARCHIVE" 'no partial'
testequal '14' grep -c '200%20URI%20Start' ./download.log
testequal '14' grep -c '201%20URI%20Done' ./download.log
testequal '8' grep -c '^ @ Queue: Action combined' ./download.log
tworepos 'file' "$APTARCHIVE" 'hit'
testequal '6' grep -c '200%20URI%20Start' ./download.log
testequal '6' grep -c '201%20URI%20Done' ./download.log
testequal '0' grep -c '^ @ Queue: Action combined' ./download.log
rm -rf rootdir/var/lib/apt/lists

changetowebserver

tworepos 'http' "//localhost:${APTHTTPPORT}" 'no partial'
testequal '12' grep -c '200%20URI%20Start' ./download.log
testequal '12' grep -c '201%20URI%20Done' ./download.log
testequal '8' grep -c '^ @ Queue: Action combined' ./download.log
tworepos 'http' "//localhost:${APTHTTPPORT}" 'hit'
testequal '2' grep -c '200%20URI%20Start' ./download.log
testequal '4' grep -c '201%20URI%20Done' ./download.log
testequal '0' grep -c '^ @ Queue: Action combined' ./download.log
rm -rf rootdir/var/lib/apt/lists