Rewrite the test suite for better compat and stability
[tinc] / test / legacy-protocol.test
index 5205877..3446621 100755 (executable)
@@ -1,84 +1,90 @@
 #!/bin/sh
 
-# Skip this test if the legacy protocol is disabled
-if grep -q "define DISABLE_LEGACY 1" "${0%/*}/../config.h"; then
-       exit 77
-fi
-
+# shellcheck source=testlib.sh
 . "${0%/*}/testlib.sh"
 
-# Initialize two nodes
+echo [STEP] Initialize two nodes
 
-$tinc $c1 <<EOF
+tinc foo <<EOF
 init foo
 set DeviceType dummy
-set Port 32753
+set Port 30060
 set Address localhost
-set PingTimeout 1
+add Subnet 10.98.98.1
+set PingTimeout 2
 EOF
 
-$tinc $c2 <<EOF
+tinc bar <<EOF
 init bar
 set DeviceType dummy
 set Port 0
-set PingTimeout 1
-set MaxTimeout 1
+add Subnet 10.98.98.2
+set PingTimeout 2
+set MaxTimeout 2
 EOF
 
-# Exchange host config files
+echo [STEP] Exchange host config files
+
+tinc foo export | tinc bar exchange | tinc foo import
+tinc bar add ConnectTo foo
 
-$tinc $c1 export | $tinc $c2 exchange | $tinc $c1 import
-$tinc $c2 add ConnectTo foo
+echo [STEP] Foo 1.1, bar 1.0
 
-# Foo 1.1, bar 1.0
+tinc bar set ExperimentalProtocol no
+tinc foo del bar.Ed25519PublicKey
+tinc bar del foo.Ed25519PublicKey
 
-$tinc $c2 set ExperimentalProtocol no
-$tinc $c1 del bar.Ed25519PublicKey
-$tinc $c2 del foo.Ed25519PublicKey
+create_script foo hosts/bar-up
+create_script bar hosts/foo-up
 
-$tinc $c1 start $r1
-$tinc $c2 start $r2
+start_tinc foo
+start_tinc bar
 
-sleep 1
+wait_script foo hosts/bar-up
+wait_script bar hosts/foo-up
 
-test `$tinc $c1 dump reachable nodes | wc -l` = 2
-test `$tinc $c2 dump reachable nodes | wc -l` = 2
+require_nodes foo 2
+require_nodes bar 2
 
-$tinc $c2 stop
-$tinc $c1 stop
+tinc bar stop
+tinc foo stop
 
-test -z "`$tinc $c1 get bar.Ed25519PublicKey`"
-test -z "`$tinc $c2 get foo.Ed25519PublicKey`"
+test -z "$(tinc foo get bar.Ed25519PublicKey)"
+test -z "$(tinc bar get foo.Ed25519PublicKey)"
 
-# Foo 1.1, bar upgrades to 1.1
+echo [STEP] Foo 1.1, bar upgrades to 1.1
 
-$tinc $c2 del ExperimentalProtocol
+tinc bar del ExperimentalProtocol
 
-$tinc $c1 start $r1
-$tinc $c2 start $r2
+start_tinc foo
+start_tinc bar
 
-sleep 5
+wait_script foo hosts/bar-up
+wait_script bar hosts/foo-up
 
-test `$tinc $c1 dump reachable nodes | wc -l` = 2
-test `$tinc $c2 dump reachable nodes | wc -l` = 2
+require_nodes foo 2
+require_nodes bar 2
 
-$tinc $c2 stop
-$tinc $c1 stop
+tinc bar stop
+tinc foo stop
 
-test -n "`$tinc $c1 get bar.Ed25519PublicKey`"
-test -n "`$tinc $c2 get foo.Ed25519PublicKey`"
+test -n "$(tinc foo get bar.Ed25519PublicKey)"
+test -n "$(tinc bar get foo.Ed25519PublicKey)"
 
-# Bar downgrades, must no longer be allowed to connect
+echo [STEP] Bar downgrades, must no longer be allowed to connect
 
-$tinc $c2 set ExperimentalProtocol no
+tinc bar set ExperimentalProtocol no
 
-$tinc $c1 start $r1
-$tinc $c2 start $r2
+create_script foo subnet-up
+start_tinc foo
+wait_script foo subnet-up
 
-sleep 5
+create_script bar subnet-up
+start_tinc bar
+wait_script bar subnet-up
 
-test `$tinc $c1 dump reachable nodes | wc -l` = 1
-test `$tinc $c2 dump reachable nodes | wc -l` = 1
+# There is no reliable way to wait for 'not connecting'.
+sleep 10
 
-$tinc $c2 stop
-$tinc $c1 stop
+require_nodes foo 1
+require_nodes bar 1