From 9848b4ac3e286bb5790482689d87c3066d1b0142 Mon Sep 17 00:00:00 2001
From: Christian Decker <decker.christian@gmail.com>
Date: Wed, 28 Sep 2016 17:06:28 +0200
Subject: [PATCH] travis-ci: Added travis-ci config

Added .travis.yml to get travis-ci to build and run tests for us.

In addition this fixes a flaky test due to the fact that when lightning2
connects to lightning3 and we tell lightning3 to restart, then
lightning2 will back-off its reconnection attempts, potentially causing
a timeout to trigger during tests. This was triggered by travis-ci
relatively consistently since the restart would take quite some
time. Now simply restarting them in reverse order and a small timeout
seems to fix this consistently.
---
 .travis.yml              | 26 ++++++++++++++++++++++++++
 daemon/test/test-routing |  4 +++-
 2 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 .travis.yml

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 000000000..b1b5119e9
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,26 @@
+sudo: required
+dist: trusty
+language: c
+before_install:
+  - sudo add-apt-repository ppa:bitcoin/bitcoin -y
+  - sudo add-apt-repository ppa:ondrej/pkg-nlnetlabs -y || true # This fails due to UTF-8 in the author's name...
+  - sudo add-apt-repository ppa:chris-lea/libsodium -y
+  - sudo apt-get -qq update
+install:
+  - sudo apt-get install -y --no-install-recommends bitcoind build-essential automake eatmydata net-tools libtool libprotobuf-c-dev libsodium-dev libsqlite3-dev valgrind protobuf-c-compiler libgmp-dev
+  - git clone https://github.com/luke-jr/libbase58.git libbase58; cd libbase58; ./autogen.sh; ./configure; make; sudo make install; cd ..
+  - git clone https://github.com/rustyrussell/lightning-rfc.git ../lightning-rfc
+compiler:
+  - gcc
+script:
+  - make clean
+  - make
+  - make full-check
+after_failure:
+  - sudo killall lightningd
+  - sudo kill `ps aux | grep lightningd | grep -v grep | awk '{print $2}'`;
+  - tar -cvjf /tmp/travis-run.tar.bz2 /tmp/lightning.*.?;
+  - curl --upload-file /tmp/travis-run.tar.bz2 https://transfer.sh/travis-run.tar.bz2;
+env:
+  global:
+    - LD_LIBRARY_PATH=/usr/local/lib
diff --git a/daemon/test/test-routing b/daemon/test/test-routing
index 17e32d05b..782e7a720 100755
--- a/daemon/test/test-routing
+++ b/daemon/test/test-routing
@@ -66,7 +66,7 @@ if [ "$RECONNECT" = restart ]; then
 	exit 1
     fi
 fi
-    
+
 [ "`lcli3 listinvoice RHASH | tr -s '\012\011\" ' ' '`" = "[ { label : RHASH , rhash : $RHASH , msatoshi : $HTLC_AMOUNT, complete : false } ] " ]
 # Pay correctly.
 lcli1 sendpay "$ROUTE" $RHASH
@@ -80,6 +80,8 @@ check lcli3 "getpeers | $FGREP \"\\\"our_amount\\\" : $(($HTLC_AMOUNT - $NO_HTLC
 if [ "$RECONNECT" = restart ]; then
     echo RESTARTING NODE3
     $LCLI3 -- dev-restart $LIGHTNINGD3 >/dev/null 2>&1 || true
+    sleep 5
+    $LCLI2 -- dev-restart $LIGHTNINGD2 >/dev/null 2>&1 || true
     if ! check "$LCLI3 getpeers 2>/dev/null | tr -s '\012\011\" ' ' ' | fgrep -q 'connected : true'"; then
 	echo "Failed to reconnect!">&2
 	exit 1