xref: /5.5.2/couchdb/test/ci/dotest (revision 4713a04d)
1#!/bin/bash
2
3source ~/.cienv
4
5echo '</pre><h3>Testing</h3><pre>'
6
7if [ "$WORKSPACE" = "" ]; then
8  echo 'WORKSPACE not set'
9  exit 2
10fi
11
12if [ "$MODE" = "" ]; then
13  echo 'MODE not set'
14  exit 2
15fi
16
17if [ "$TS" = "" ]; then
18  TS="adhoc"
19fi
20
21start_cluster() {
22  echo "Starting server"
23  for a in {1..3}; do
24    echo "Starting server: attempt $a"
25    stop_cluster
26    cd $WORKSPACE/ns_server
27    ./cluster_run -n4 1>$WORKSPACE/run.log 2>&1 &
28    disown
29    for i in {1..120}; do
30      grep -qs 'Couchbase Server has started' logs/n_0/info.log && \
31        grep -qs 'Couchbase Server has started' logs/n_1/info.log && \
32          wget -qO- http://localhost:9000/ &>/dev/null &&
33            wget -qO- http://localhost:9001/ &>/dev/null &&
34              ok_run=1 && break
35      sleep 3
36    done
37    sleep 30
38    test "$ok_run" && break
39  done
40  test "$ok_run" || error_exit "Server startup failed even after 3 tries"
41}
42
43stop_cluster() {
44  pkill -f cluster_
45  pkill -f $WORKSPACE/install/bin
46  pkill -f testrunner
47  pkill -f $WORKSPACE/install
48  pkill -f testrunner
49  killall beam.smp epmd memcached eventing-producer eventing-consumer python memcached.json 1>/dev/null 2>&1
50  sleep 10
51  killall -9 beam.smp epmd memcached eventing-producer eventing-consumer python memcached.json 1>/dev/null 2>&1
52  cd $WORKSPACE/ns_server
53  make dataclean 1>/dev/null 2>&1
54  sudo rm -f /tmp/core*
55  sleep 10
56}
57
58collect_logs() {
59  if [ "$phase" = "" ]; then phase=unknown; fi
60  tar -C $WORKSPACE --transform "s/^/logs-$phase-/" -uf $WORKSPACE/logs.tar ns_server/logs 1>/dev/null 2>&1
61  tar -C $WORKSPACE --transform "s/^/logs-$phase-/" -uf $WORKSPACE/logs.tar testrunner/logs 1>/dev/null 2>&1
62  tar -C $WORKSPACE --transform "s/^/logs-$phase-/" -uf $WORKSPACE/logs.tar test.log 1>/dev/null 2>&1
63  tar -C $WORKSPACE --transform "s/^/logs-$phase-/" -uf $WORKSPACE/logs.tar run.log 1>/dev/null 2>&1
64}
65
66error_email() {
67  if [ ! -f ~/.cigreen ]; then return; fi
68  rm ~/.cigreen
69
70  if test "`find ~ -maxdepth 1 -name .cinotify -mmin -1440`"; then return; fi
71  touch ~/.cinotify
72
73  if [ "$WATCHERS" = "" ]; then return; fi
74  cat /var/www/views-current.html | \
75     sendemail -q \
76       -s west.smtp.mx.exch029.serverdata.net:25 \
77       -f 'Views CI <community_admin@couchbase.com>' \
78       -t $WATCHERS \
79       -u 'Views CI just broke'
80}
81
82error_exit() {
83  echo "</pre><h4>Testing Failed: $1</h4><pre>"
84  echo "$2"
85  collect_logs
86  stop_cluster
87  error_email
88  exit 2
89}
90
91# Setup workspace
92echo "Testing mode: $MODE"
93stop_cluster
94rm -f $WORKSPACE/logs.tar.* $WORKSPACE/test.log $WORKSPACE/run.log /tmp/core-*
95> $WORKSPACE/test.log
96
97# Test the base
98echo "</pre><h4>Simple Test</h4><pre>"
99export phase=sanity
100cd $WORKSPACE/testrunner
101(timeout 1h make simple-test 2>&1 | ts) | tee -a $WORKSPACE/test.log | egrep 'pass|fail|summary|ok$'
102
103# Unit tests
104echo "</pre><h4>Unit Tests with dialyzer</h4><pre>"
105export phase=sanity
106cd $WORKSPACE/build/couchdb
107(timeout 2h make check 2>&1 | ts) | tee -a $WORKSPACE/test.log | egrep 'pass|fail|summary|ok$'
108
109# Test the premerge tests
110echo "</pre><h4>Views Pre merge test without createdelete views</h4><pre>"
111export phase=sanity
112cd $WORKSPACE/testrunner
113(timeout 1h make test-views-pre-merge-viewci 2>&1 | ts) | tee -a $WORKSPACE/test.log | egrep 'pass|fail|summary|ok$'
114
115# Test the viewmerge tests
116echo "</pre><h4>Viewmerge tests without devview test</h4><pre>"
117export phase=sanity
118cd $WORKSPACE/testrunner
119(timeout 1h make test-viewmerge-viewci 2>&1 | ts) | tee -a $WORKSPACE/test.log | egrep 'pass|fail|summary|ok$'
120
121# Functional tests
122export phase=functional
123start_cluster
124ulimit -c 2097152
125sudo bash -c "echo /tmp/core-%e.$TS.%p > /proc/sys/kernel/core_pattern"
126perl -pi -e 's/num_files, 10/num_files, 50/' $WORKSPACE/install/etc/couchbase/static_config
127(timeout 1h echo "No functional tests defined" 2>&1 | ts) | tee -a $WORKSPACE/test.log | egrep 'pass|fail|summary|ok$'
128collect_logs
129stop_cluster
130
131# Integration tests
132echo "</pre><h4>Integration tests</h4><pre>"
133export phase=integration
134cd $WORKSPACE/testrunner
135(timeout 2h "No integration tests defined" 2>&1 | ts) | tee -a $WORKSPACE/test.log
136collect_logs
137
138# Verify results
139> /tmp/fail.log
140cd $WORKSPACE/couchdb
141grep 'make:\s\*\*\*\s\[test-view.*\]\s' $WORKSPACE/test.log >> /tmp/fail.log
142grep '\sfail\s*$' $WORKSPACE/test.log >> /tmp/fail.log
143grep 'FAIL\s*github.com/couchbase' $WORKSPACE/test.log >> /tmp/fail.log
144grep -- '--- FAIL:' $WORKSPACE/test.log >> /tmp/fail.log
145grep '^\s*2i' $WORKSPACE/test.log | grep 'fail\s*$' >> /tmp/fail.log
146skiplist="`cat test/ci/skip.txt`"
147for tst in $skiplist; do
148  echo "$tst" | grep -qs '^\s*#' && continue
149  echo "$tst" | grep -qs '^\s*$' && continue
150  grep -v "$tst" /tmp/fail.log > /tmp/fail-out.log
151  mv /tmp/fail-out.log /tmp/fail.log
152done
153faillog="`cat /tmp/fail.log`"
154if [ "$faillog" != "" ]; then error_exit "Required test failed" "$faillog"; fi
155echo "</pre><h4>Testing Succeeded</h4><pre>"
156if [ "$skiplist" != "" ]; then
157  echo "But we ignored these tests:"
158  echo "$skiplist"
159fi
160echo
161
162# Note versions
163cd $WORKSPACE/goproj/src/github.com/couchbase/eventing
164git rev-parse HEAD > ~/eventing.good
165cd $WORKSPACE/goproj/src/github.com/couchbase/indexing
166git rev-parse HEAD > ~/indexing.good
167cd $WORKSPACE/goproj/src/github.com/couchbase/query
168git rev-parse HEAD > ~/query.good
169cd $WORKSPACE/goproj/src/github.com/couchbase/gometa
170git rev-parse HEAD > ~/gometa.good
171cd $WORKSPACE/forestdb
172git rev-parse HEAD > ~/forestdb.good
173cd $WORKSPACE/ns_server
174git rev-parse HEAD > ~/ns_server.good
175cd $WORKSPACE/couchdb
176git rev-parse HEAD > ~/couchdb.good
177cd $WORKSPACE/couchstore
178git rev-parse HEAD > ~/couchstore.good
179cd $WORKSPACE/goproj/src/github.com/couchbase/plasma
180git rev-parse HEAD > ~/plasma.good
181cd $WORKSPACE/goproj/src/github.com/couchbase/nitro
182git rev-parse HEAD > ~/nitro.good
183cd $WORKSPACE/testrunner
184git rev-parse HEAD > ~/testrunner.good
185cd $WORKSPACE/kv_engine
186git rev-parse HEAD > ~/kv_engine.good
187
188touch ~/.cigreen
189exit 0
190
191