Implement initial Python bindings for Open vSwitch database.
[sliver-openvswitch.git] / tests / reconnect.at
index 33e4b95..5598364 100644 (file)
@@ -1,23 +1,41 @@
 AT_BANNER([reconnect library])
 
+m4_define([__RECONNECT_CHECK],
+  [AT_SETUP([$1])
+   $2
+   AT_KEYWORDS([reconnect])
+   AT_DATA([input], [$3])
+   AT_CHECK([$4], [0], [$5])
+   AT_CLEANUP])
+
+m4_define([RECONNECT_CHECK],
+  [__RECONNECT_CHECK(
+     [$1 - C],
+     [],
+     [$2],
+     [test-reconnect < input],
+     [$3])
+   __RECONNECT_CHECK(
+     [$1 - Python],
+     [AT_SKIP_IF([test $HAVE_PYTHON = no])],
+     [$2],
+     [$PYTHON $srcdir/test-reconnect.py < input],
+     [$3])])
+
 ######################################################################
-AT_SETUP([nothing happens if not enabled])
-AT_KEYWORDS([reconnect])
-AT_DATA([input], [run
+RECONNECT_CHECK([nothing happens if not enabled],
+  [run
 timeout
-])
-OVS_CHECK_LCOV([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 run
 timeout
   no timeout
 ])
-AT_CLEANUP
 
 ######################################################################
-AT_SETUP([quick connect, idle disconnect])
-AT_KEYWORDS([reconnect])
-AT_DATA([input], [enable
+RECONNECT_CHECK([quick connect, idle disconnect],
+  [enable
 
 # Connection succeeds.
 run
@@ -31,8 +49,7 @@ run
 timeout
 run
 disconnected
-])
-OVS_CHECK_LCOV([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
@@ -70,12 +87,10 @@ disconnected
   1 successful connections out of 1 attempts, seqno 2
   not connected (0 ms), total 10000 ms connected
 ])
-AT_CLEANUP
 
 ######################################################################
-AT_SETUP([slow connect, idle disconnect])
-AT_KEYWORDS([reconnect])
-AT_DATA([input], [enable
+RECONNECT_CHECK([slow connect, idle disconnect],
+  [enable
 
 # Start connecting.
 run
@@ -94,8 +109,7 @@ run
 timeout
 run
 disconnected
-])
-OVS_CHECK_LCOV([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
@@ -104,15 +118,14 @@ enable
 run
   should connect
 connecting
-  in CONNECTING for 0 ms (0 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (0 ms backoff)
 
 # Connect after 500 ms.
 advance 500
 
 ### t=1500 ###
-  in CONNECTING for 500 ms (0 ms backoff)
+  in CONNECT_IN_PROGRESS for 500 ms (0 ms backoff)
 run
-  should connect
 connected
   in ACTIVE for 0 ms (0 ms backoff)
   created 1000, last received 1000, last connected 1500
@@ -144,12 +157,10 @@ disconnected
   1 successful connections out of 1 attempts, seqno 2
   not connected (0 ms), total 10000 ms connected
 ])
-AT_CLEANUP
 
 ######################################################################
-AT_SETUP([connect backs off])
-AT_KEYWORDS([reconnect])
-AT_DATA([input], [enable
+RECONNECT_CHECK([connect backs off],
+  [enable
 
 # First connection attempt fails after 1000 ms.
 run
@@ -208,8 +219,7 @@ connecting
 timeout
 run
 connect-failed
-])
-OVS_CHECK_LCOV([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
@@ -218,14 +228,13 @@ enable
 run
   should connect
 connecting
-  in CONNECTING for 0 ms (0 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (0 ms backoff)
 run
-  should connect
 timeout
   advance 1000 ms
 
 ### t=2000 ###
-  in CONNECTING for 1000 ms (0 ms backoff)
+  in CONNECT_IN_PROGRESS for 1000 ms (0 ms backoff)
 run
   should disconnect
 connect-failed
@@ -243,12 +252,12 @@ run
 
 # Second connection attempt fails after 1000 ms.
 connecting
-  in CONNECTING for 0 ms (1000 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (1000 ms backoff)
 timeout
   advance 1000 ms
 
 ### t=4000 ###
-  in CONNECTING for 1000 ms (1000 ms backoff)
+  in CONNECT_IN_PROGRESS for 1000 ms (1000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -266,12 +275,12 @@ run
 
 # Third connection attempt fails after 2000 ms.
 connecting
-  in CONNECTING for 0 ms (2000 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (2000 ms backoff)
 timeout
   advance 2000 ms
 
 ### t=8000 ###
-  in CONNECTING for 2000 ms (2000 ms backoff)
+  in CONNECT_IN_PROGRESS for 2000 ms (2000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -289,12 +298,12 @@ run
 
 # Third connection attempt fails after 4000 ms.
 connecting
-  in CONNECTING for 0 ms (4000 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (4000 ms backoff)
 timeout
   advance 4000 ms
 
 ### t=16000 ###
-  in CONNECTING for 4000 ms (4000 ms backoff)
+  in CONNECT_IN_PROGRESS for 4000 ms (4000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -312,12 +321,12 @@ run
 
 # Third connection attempt fails after 8000 ms.
 connecting
-  in CONNECTING for 0 ms (8000 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (8000 ms backoff)
 timeout
   advance 8000 ms
 
 ### t=32000 ###
-  in CONNECTING for 8000 ms (8000 ms backoff)
+  in CONNECT_IN_PROGRESS for 8000 ms (8000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -335,24 +344,22 @@ run
 
 # Fourth connection attempt fails after 8000 ms.
 connecting
-  in CONNECTING for 0 ms (8000 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (8000 ms backoff)
 timeout
   advance 8000 ms
 
 ### t=48000 ###
-  in CONNECTING for 8000 ms (8000 ms backoff)
+  in CONNECT_IN_PROGRESS for 8000 ms (8000 ms backoff)
 run
   should disconnect
 connect-failed
   in BACKOFF for 0 ms (8000 ms backoff)
   0 successful connections out of 6 attempts, seqno 0
 ])
-AT_CLEANUP
 
 ######################################################################
-AT_SETUP([connections with no data preserve backoff])
-AT_KEYWORDS([reconnect])
-AT_DATA([input], [enable
+RECONNECT_CHECK([connections with no data preserve backoff],
+  [enable
 
 # First connect, then idle timeout kills connection.
 run
@@ -508,14 +515,11 @@ timeout
 
 ### t=38000 ###
   in BACKOFF for 4000 ms (4000 ms backoff)
-
 ])
-AT_CLEANUP
 
 ######################################################################
-AT_SETUP([brief connection preserves backoff])
-AT_KEYWORDS([reconnect])
-AT_DATA([input], [enable
+RECONNECT_CHECK([brief connection preserves backoff],
+  [enable
 
 # First connection attempt fails after 1000 ms.
 run
@@ -553,9 +557,7 @@ run
 # Back off for 4000 ms.
 timeout
 run
-])
-OVS_CHECK_LCOV([test-reconnect < input], [0], 
-  [### t=1000 ###
+], [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
 
@@ -563,14 +565,13 @@ enable
 run
   should connect
 connecting
-  in CONNECTING for 0 ms (0 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (0 ms backoff)
 run
-  should connect
 timeout
   advance 1000 ms
 
 ### t=2000 ###
-  in CONNECTING for 1000 ms (0 ms backoff)
+  in CONNECT_IN_PROGRESS for 1000 ms (0 ms backoff)
 run
   should disconnect
 connect-failed
@@ -588,12 +589,12 @@ run
 
 # Second connection attempt fails after 1000 ms.
 connecting
-  in CONNECTING for 0 ms (1000 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (1000 ms backoff)
 timeout
   advance 1000 ms
 
 ### t=4000 ###
-  in CONNECTING for 1000 ms (1000 ms backoff)
+  in CONNECT_IN_PROGRESS for 1000 ms (1000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -611,13 +612,12 @@ run
 
 # Third connection attempt succeeds after 500 ms.
 connecting
-  in CONNECTING for 0 ms (2000 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (2000 ms backoff)
 advance 500
 
 ### t=6500 ###
-  in CONNECTING for 500 ms (2000 ms backoff)
+  in CONNECT_IN_PROGRESS for 500 ms (2000 ms backoff)
 run
-  should connect
 connected
   in ACTIVE for 0 ms (2000 ms backoff)
   created 1000, last received 1000, last connected 6500
@@ -645,12 +645,10 @@ timeout
 run
   should connect
 ])
-AT_CLEANUP
 
 ######################################################################
-AT_SETUP([brief connection with data preserves backoff])
-AT_KEYWORDS([reconnect])
-AT_DATA([input], [enable
+RECONNECT_CHECK([brief connection with data preserves backoff],
+  [enable
 
 # First connection attempt fails after 1000 ms.
 run
@@ -698,8 +696,7 @@ run
 # Back off for 4000 ms.
 timeout
 run
-])
-OVS_CHECK_LCOV([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
@@ -708,14 +705,13 @@ enable
 run
   should connect
 connecting
-  in CONNECTING for 0 ms (0 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (0 ms backoff)
 run
-  should connect
 timeout
   advance 1000 ms
 
 ### t=2000 ###
-  in CONNECTING for 1000 ms (0 ms backoff)
+  in CONNECT_IN_PROGRESS for 1000 ms (0 ms backoff)
 run
   should disconnect
 connect-failed
@@ -733,12 +729,12 @@ run
 
 # Second connection attempt fails after 1000 ms.
 connecting
-  in CONNECTING for 0 ms (1000 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (1000 ms backoff)
 timeout
   advance 1000 ms
 
 ### t=4000 ###
-  in CONNECTING for 1000 ms (1000 ms backoff)
+  in CONNECT_IN_PROGRESS for 1000 ms (1000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -756,13 +752,12 @@ run
 
 # Third connection attempt succeeds after 500 ms.
 connecting
-  in CONNECTING for 0 ms (2000 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (2000 ms backoff)
 advance 500
 
 ### t=6500 ###
-  in CONNECTING for 500 ms (2000 ms backoff)
+  in CONNECT_IN_PROGRESS for 500 ms (2000 ms backoff)
 run
-  should connect
 connected
   in ACTIVE for 0 ms (2000 ms backoff)
   created 1000, last received 1000, last connected 6500
@@ -811,12 +806,10 @@ timeout
 run
   should connect
 ])
-AT_CLEANUP
 
 ######################################################################
-AT_SETUP([long connection resets backoff])
-AT_KEYWORDS([reconnect])
-AT_DATA([input], [enable
+RECONNECT_CHECK([long connection resets backoff],
+  [enable
 
 # First connection attempt fails after 1000 ms.
 run
@@ -864,8 +857,7 @@ run
 # Back off for 1000 ms.
 timeout
 run
-])
-OVS_CHECK_LCOV([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
@@ -874,14 +866,13 @@ enable
 run
   should connect
 connecting
-  in CONNECTING for 0 ms (0 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (0 ms backoff)
 run
-  should connect
 timeout
   advance 1000 ms
 
 ### t=2000 ###
-  in CONNECTING for 1000 ms (0 ms backoff)
+  in CONNECT_IN_PROGRESS for 1000 ms (0 ms backoff)
 run
   should disconnect
 connect-failed
@@ -899,12 +890,12 @@ run
 
 # Second connection attempt fails after 1000 ms.
 connecting
-  in CONNECTING for 0 ms (1000 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (1000 ms backoff)
 timeout
   advance 1000 ms
 
 ### t=4000 ###
-  in CONNECTING for 1000 ms (1000 ms backoff)
+  in CONNECT_IN_PROGRESS for 1000 ms (1000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -922,13 +913,12 @@ run
 
 # Third connection attempt succeeds after 500 ms.
 connecting
-  in CONNECTING for 0 ms (2000 ms backoff)
+  in CONNECT_IN_PROGRESS for 0 ms (2000 ms backoff)
 advance 500
 
 ### t=6500 ###
-  in CONNECTING for 500 ms (2000 ms backoff)
+  in CONNECT_IN_PROGRESS for 500 ms (2000 ms backoff)
 run
-  should connect
 connected
   in ACTIVE for 0 ms (2000 ms backoff)
   created 1000, last received 1000, last connected 6500
@@ -977,12 +967,10 @@ timeout
 run
   should connect
 ])
-AT_CLEANUP
 
 ######################################################################
-AT_SETUP([connection attempt fails quickly])
-AT_KEYWORDS([reconnect])
-AT_DATA([input], [enable
+RECONNECT_CHECK([connection attempt fails quickly],
+  [enable
 
 # Connection fails quickly.
 run
@@ -999,9 +987,8 @@ connect-failed ECONNREFUSED
 # Back off for 2000 ms.
 run
 timeout
-])
-OVS_CHECK_LCOV([test-reconnect < input], [0], 
-  [### t=1000 ###
+],
+   [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
 
@@ -1035,5 +1022,195 @@ timeout
 ### t=4000 ###
   in BACKOFF for 2000 ms (2000 ms backoff)
 ])
-AT_CLEANUP
 
+######################################################################
+RECONNECT_CHECK([max-tries of 1 honored],
+  [set-max-tries 1
+enable
+
+# Connection succeeds.
+run
+connected
+
+# Send inactivity probe.
+timeout
+run
+
+# Idle timeout kills connection.
+timeout
+run
+disconnected
+],
+  [### t=1000 ###
+set-max-tries 1
+  1 tries left
+enable
+  in BACKOFF for 0 ms (0 ms backoff)
+  0 tries left
+
+# Connection succeeds.
+run
+  should connect
+connected
+  in ACTIVE for 0 ms (0 ms backoff)
+  1 successful connections out of 1 attempts, seqno 1
+  connected (0 ms), total 0 ms connected
+
+# Send inactivity probe.
+timeout
+  advance 5000 ms
+
+### t=6000 ###
+  in ACTIVE for 5000 ms (0 ms backoff)
+  connected (5000 ms), total 5000 ms connected
+run
+  should send probe
+  in IDLE for 0 ms (0 ms backoff)
+
+# Idle timeout kills connection.
+timeout
+  advance 5000 ms
+
+### t=11000 ###
+  in IDLE for 5000 ms (0 ms backoff)
+  connected (10000 ms), total 10000 ms connected
+run
+  should disconnect
+disconnected
+  in VOID for 0 ms (1000 ms backoff)
+  1 successful connections out of 1 attempts, seqno 2
+  not connected (0 ms), total 10000 ms connected
+])
+
+######################################################################
+RECONNECT_CHECK([max-tries of 0 honored],
+  [set-max-tries 0
+enable
+run
+timeout
+],
+  [### t=1000 ###
+set-max-tries 0
+  0 tries left
+enable
+run
+timeout
+  no timeout
+])
+
+######################################################################
+RECONNECT_CHECK([passive mode],
+  [passive
+enable
+
+# Start listening.
+timeout
+run
+listening
+
+# Listening never times out.
+timeout
+run
+
+# Listening failed (accept() returned funny error?).  Back off and try again.
+listen-error 0
+timeout
+run
+listening
+
+# Connection accepted.
+connected
+received
+advance 1000
+received
+
+# Connection times out.
+timeout
+run
+timeout
+run
+disconnected
+
+# Start listening again.
+timeout
+run
+listening
+],
+  [### t=1000 ###
+passive
+enable
+  in BACKOFF for 0 ms (0 ms backoff)
+
+# Start listening.
+timeout
+  advance 0 ms
+run
+  should connect
+listening
+  in LISTENING for 0 ms (0 ms backoff)
+
+# Listening never times out.
+timeout
+  no timeout
+run
+
+# Listening failed (accept() returned funny error?).  Back off and try again.
+listen-error 0
+  in BACKOFF for 0 ms (1000 ms backoff)
+timeout
+  advance 1000 ms
+
+### t=2000 ###
+  in BACKOFF for 1000 ms (1000 ms backoff)
+run
+  should connect
+listening
+  in LISTENING for 0 ms (1000 ms backoff)
+
+# Connection accepted.
+connected
+  in ACTIVE for 0 ms (1000 ms backoff)
+  created 1000, last received 1000, last connected 2000
+  1 successful connections out of 1 attempts, seqno 1
+  connected (0 ms), total 0 ms connected
+received
+  created 1000, last received 2000, last connected 2000
+advance 1000
+
+### t=3000 ###
+  in ACTIVE for 1000 ms (1000 ms backoff)
+  connected (1000 ms), total 1000 ms connected
+received
+  created 1000, last received 3000, last connected 2000
+
+# Connection times out.
+timeout
+  advance 5000 ms
+
+### t=8000 ###
+  in ACTIVE for 6000 ms (1000 ms backoff)
+  connected (6000 ms), total 6000 ms connected
+run
+  should send probe
+  in IDLE for 0 ms (1000 ms backoff)
+timeout
+  advance 5000 ms
+
+### t=13000 ###
+  in IDLE for 5000 ms (1000 ms backoff)
+  connected (11000 ms), total 11000 ms connected
+run
+  should disconnect
+disconnected
+  in BACKOFF for 0 ms (0 ms backoff)
+  1 successful connections out of 1 attempts, seqno 2
+  not connected (0 ms), total 11000 ms connected
+
+# Start listening again.
+timeout
+  advance 0 ms
+run
+  should connect
+listening
+  in LISTENING for 0 ms (0 ms backoff)
+])