chiark / gitweb /
Mirroring: Tests: search for expected messages
[dgit.git] / tests / tests / mirror
1 #!/bin/bash
2 set -e
3 . tests/lib
4
5 t-drs
6
7 : ---- "setup up the mirror hook in a basic way" ----
8
9 reposmirror=$tmp/git-mirror
10 queuedir=$tmp/git/_mirror-queue
11 mkdir $reposmirror
12
13 mhook=$drs_dispatch/mirror-hook
14 ln -sf ${DGIT_INFRA_PFX}dgit-mirror-rsync $mhook
15 mhook () {
16         "$mhook" "$drs_dispatch" "$@"
17 }
18
19 >$drs_dispatch/mirror-settings
20 mset () { echo >>$drs_dispatch/mirror-settings "$1"; }
21
22 mset remoterepos="$reposmirror"
23
24 commit-build-push-expect-log () {
25         local msg=$1
26         local mpat=$2
27         t-commit "$msg"
28         t-dgit build
29         LC_MESSAGES=C \
30         t-dgit push --new 2>&1 |tee $tmp/push.log
31         t-grep-mpat "$mpat" $tmp/push.log
32 }
33
34 check-mirrored () {
35         t-reporefs master
36         t-reporefs mirror $pmirror
37         diff $tmp/show-refs.{master,mirror}
38         cat $queuedir/$p.log
39         t-files-notexist $queuedir/$p.{n,a,lock,err}
40 }
41
42 check-not-mirrored () {
43         # uses previous t-reporefs-master
44         t-reporefs mirror $pmirror
45         diff $tmp/show-refs.{master,mirror}
46 }
47
48 : ---- "basic test" ----
49
50 t-tstunt-parsechangelog
51 t-prep-newpackage example 1.0
52
53 pmirror=$reposmirror/$p.git
54 mhook setup
55
56 cd $p
57 revision=1
58 t-dgit build
59 t-dgit push --new
60
61 check-mirrored
62
63
64 : ---- "stunt ssh test" ----
65
66 sentinel=$tmp/stunt-ssh-sentinel
67
68 cat <<END >$tmp/stunt-ssh
69 #!/bin/sh
70 set -ex
71 : $sentinel
72 cat >&2 $sentinel
73 shift # eat HOST
74 sh -c "\$*"
75 : ${sentinel}2
76 date >${sentinel}2
77 END
78 chmod +x $tmp/stunt-ssh
79
80 mset rsyncssh=$tmp/stunt-ssh
81 mset remoterepos=HOST:$reposmirror
82
83 # mirror should fail due to lack of stunt-ssh-sentinel
84
85 commit-build-push-expect-log "stunt ssh test" \
86         E:'mirror hook failed: .*exited'
87
88 ls -al $queuedir/$p.a
89 check-not-mirrored
90
91 touch $sentinel
92
93 mhook backlog
94 check-mirrored
95
96 : ----- "stall timeout test" -----
97
98 rm -f $sentinel ${sentinel}2
99 mkfifo $sentinel ${sentinel}2
100
101 mset hooktimeout=5
102
103 commit-build-push-expect-log "stall timeout test" \
104         E:'mirror hook failed: .*timeout'
105
106 check-not-mirrored
107
108 exec 3<>$sentinel
109 exec 3>&-
110 cat ${sentinel}2
111
112 check-mirrored
113
114 echo done.