ovsdb-server: Refactoring and clean up remote status reporting.
[cascardo/ovs.git] / tests / reconnect.at
index 7c1cc6a..c88ca78 100644 (file)
@@ -1,23 +1,47 @@
 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],
+     [ovstest test-reconnect < input],
+     [$3])
+   __RECONNECT_CHECK(
+     [$1 - Python2],
+     [AT_SKIP_IF([test $HAVE_PYTHON = no])],
+     [$2],
+     [$PYTHON $srcdir/test-reconnect.py < input],
+     [$3])
+   __RECONNECT_CHECK(
+     [$1 - Python3],
+     [AT_SKIP_IF([test $HAVE_PYTHON3 = no])],
+     [$2],
+     [$PYTHON3 $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
-])
-AT_CHECK([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 +55,7 @@ run
 timeout
 run
 disconnected
-])
-AT_CHECK([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
@@ -42,8 +65,10 @@ run
   should connect
 connected
   in ACTIVE for 0 ms (0 ms backoff)
+  created 1000, last activity 1000, last connected 1000
   1 successful connections out of 1 attempts, seqno 1
-  connected (0 ms), total 0 ms connected
+  connected
+  last connected 0 ms ago, connected 0 ms total
 
 # Send inactivity probe.
 timeout
@@ -51,7 +76,6 @@ timeout
 
 ### 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)
@@ -62,20 +86,18 @@ timeout
 
 ### t=11000 ###
   in IDLE for 5000 ms (0 ms backoff)
-  connected (10000 ms), total 10000 ms connected
 run
   should disconnect
 disconnected
   in BACKOFF for 0 ms (1000 ms backoff)
   1 successful connections out of 1 attempts, seqno 2
-  not connected (0 ms), total 10000 ms connected
+  disconnected
+  disconnected at 11000 ms (0 ms ago)
 ])
-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 +116,7 @@ run
 timeout
 run
 disconnected
-])
-AT_CHECK([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
@@ -104,19 +125,20 @@ enable
 run
   should connect
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (0 ms backoff)
+  in CONNECTING for 0 ms (0 ms backoff)
 
 # Connect after 500 ms.
 advance 500
 
 ### t=1500 ###
-  in CONNECT_IN_PROGRESS for 500 ms (0 ms backoff)
+  in CONNECTING for 500 ms (0 ms backoff)
 run
 connected
   in ACTIVE for 0 ms (0 ms backoff)
-  created 1000, last received 1000, last connected 1500
+  created 1000, last activity 1000, last connected 1500
   1 successful connections out of 1 attempts, seqno 1
-  connected (0 ms), total 0 ms connected
+  connected
+  last connected 0 ms ago, connected 0 ms total
 
 # Send inactivity probe.
 timeout
@@ -124,7 +146,6 @@ timeout
 
 ### t=6500 ###
   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)
@@ -135,20 +156,18 @@ timeout
 
 ### t=11500 ###
   in IDLE for 5000 ms (0 ms backoff)
-  connected (10000 ms), total 10000 ms connected
 run
   should disconnect
 disconnected
   in BACKOFF for 0 ms (1000 ms backoff)
   1 successful connections out of 1 attempts, seqno 2
-  not connected (0 ms), total 10000 ms connected
+  disconnected
+  disconnected at 11500 ms (0 ms ago)
 ])
-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
@@ -207,8 +226,7 @@ connecting
 timeout
 run
 connect-failed
-])
-AT_CHECK([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
@@ -217,13 +235,13 @@ enable
 run
   should connect
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (0 ms backoff)
+  in CONNECTING for 0 ms (0 ms backoff)
 run
 timeout
   advance 1000 ms
 
 ### t=2000 ###
-  in CONNECT_IN_PROGRESS for 1000 ms (0 ms backoff)
+  in CONNECTING for 1000 ms (0 ms backoff)
 run
   should disconnect
 connect-failed
@@ -241,12 +259,12 @@ run
 
 # Second connection attempt fails after 1000 ms.
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (1000 ms backoff)
+  in CONNECTING for 0 ms (1000 ms backoff)
 timeout
   advance 1000 ms
 
 ### t=4000 ###
-  in CONNECT_IN_PROGRESS for 1000 ms (1000 ms backoff)
+  in CONNECTING for 1000 ms (1000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -264,12 +282,12 @@ run
 
 # Third connection attempt fails after 2000 ms.
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (2000 ms backoff)
+  in CONNECTING for 0 ms (2000 ms backoff)
 timeout
   advance 2000 ms
 
 ### t=8000 ###
-  in CONNECT_IN_PROGRESS for 2000 ms (2000 ms backoff)
+  in CONNECTING for 2000 ms (2000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -287,12 +305,12 @@ run
 
 # Third connection attempt fails after 4000 ms.
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (4000 ms backoff)
+  in CONNECTING for 0 ms (4000 ms backoff)
 timeout
   advance 4000 ms
 
 ### t=16000 ###
-  in CONNECT_IN_PROGRESS for 4000 ms (4000 ms backoff)
+  in CONNECTING for 4000 ms (4000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -310,12 +328,12 @@ run
 
 # Third connection attempt fails after 8000 ms.
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (8000 ms backoff)
+  in CONNECTING for 0 ms (8000 ms backoff)
 timeout
   advance 8000 ms
 
 ### t=32000 ###
-  in CONNECT_IN_PROGRESS for 8000 ms (8000 ms backoff)
+  in CONNECTING for 8000 ms (8000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -333,24 +351,22 @@ run
 
 # Fourth connection attempt fails after 8000 ms.
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (8000 ms backoff)
+  in CONNECTING for 0 ms (8000 ms backoff)
 timeout
   advance 8000 ms
 
 ### t=48000 ###
-  in CONNECT_IN_PROGRESS for 8000 ms (8000 ms backoff)
+  in CONNECTING 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
@@ -398,14 +414,15 @@ run
   should connect
 connected
   in ACTIVE for 0 ms (0 ms backoff)
+  created 1000, last activity 1000, last connected 1000
   1 successful connections out of 1 attempts, seqno 1
-  connected (0 ms), total 0 ms connected
+  connected
+  last connected 0 ms ago, connected 0 ms total
 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)
@@ -414,13 +431,13 @@ timeout
 
 ### t=11000 ###
   in IDLE for 5000 ms (0 ms backoff)
-  connected (10000 ms), total 10000 ms connected
 run
   should disconnect
 disconnected
   in BACKOFF for 0 ms (1000 ms backoff)
   1 successful connections out of 1 attempts, seqno 2
-  not connected (0 ms), total 10000 ms connected
+  disconnected
+  disconnected at 11000 ms (0 ms ago)
 
 # Back off for 1000 ms.
 timeout
@@ -428,6 +445,7 @@ timeout
 
 ### t=12000 ###
   in BACKOFF for 1000 ms (1000 ms backoff)
+  last connected 11000 ms ago, connected 10000 ms total
 run
   should connect
 
@@ -436,15 +454,15 @@ run
   should connect
 connected
   in ACTIVE for 0 ms (1000 ms backoff)
-  created 1000, last received 1000, last connected 12000
+  created 1000, last activity 1000, last connected 12000
   2 successful connections out of 2 attempts, seqno 3
-  connected (0 ms), total 10000 ms connected
+  connected
+  last connected 0 ms ago, connected 10000 ms total
 timeout
   advance 5000 ms
 
 ### t=17000 ###
   in ACTIVE for 5000 ms (1000 ms backoff)
-  connected (5000 ms), total 15000 ms connected
 run
   should send probe
   in IDLE for 0 ms (1000 ms backoff)
@@ -453,13 +471,13 @@ timeout
 
 ### t=22000 ###
   in IDLE for 5000 ms (1000 ms backoff)
-  connected (10000 ms), total 20000 ms connected
 run
   should disconnect
 disconnected
   in BACKOFF for 0 ms (2000 ms backoff)
   2 successful connections out of 2 attempts, seqno 4
-  not connected (0 ms), total 20000 ms connected
+  disconnected
+  disconnected at 22000 ms (0 ms ago)
 
 # Back off for 2000 ms.
 timeout
@@ -467,6 +485,7 @@ timeout
 
 ### t=24000 ###
   in BACKOFF for 2000 ms (2000 ms backoff)
+  last connected 12000 ms ago, connected 20000 ms total
 run
   should connect
 
@@ -475,15 +494,15 @@ run
   should connect
 connected
   in ACTIVE for 0 ms (2000 ms backoff)
-  created 1000, last received 1000, last connected 24000
+  created 1000, last activity 1000, last connected 24000
   3 successful connections out of 3 attempts, seqno 5
-  connected (0 ms), total 20000 ms connected
+  connected
+  last connected 0 ms ago, connected 20000 ms total
 timeout
   advance 5000 ms
 
 ### t=29000 ###
   in ACTIVE for 5000 ms (2000 ms backoff)
-  connected (5000 ms), total 25000 ms connected
 run
   should send probe
   in IDLE for 0 ms (2000 ms backoff)
@@ -492,13 +511,13 @@ timeout
 
 ### t=34000 ###
   in IDLE for 5000 ms (2000 ms backoff)
-  connected (10000 ms), total 30000 ms connected
 run
   should disconnect
 disconnected
   in BACKOFF for 0 ms (4000 ms backoff)
   3 successful connections out of 3 attempts, seqno 6
-  not connected (0 ms), total 30000 ms connected
+  disconnected
+  disconnected at 34000 ms (0 ms ago)
 
 # Back off for 4000 ms.
 timeout
@@ -506,14 +525,12 @@ timeout
 
 ### t=38000 ###
   in BACKOFF for 4000 ms (4000 ms backoff)
-
+  last connected 14000 ms ago, connected 30000 ms total
 ])
-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
@@ -551,9 +568,7 @@ run
 # Back off for 4000 ms.
 timeout
 run
-])
-AT_CHECK([test-reconnect < input], [0], 
-  [### t=1000 ###
+], [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
 
@@ -561,13 +576,13 @@ enable
 run
   should connect
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (0 ms backoff)
+  in CONNECTING for 0 ms (0 ms backoff)
 run
 timeout
   advance 1000 ms
 
 ### t=2000 ###
-  in CONNECT_IN_PROGRESS for 1000 ms (0 ms backoff)
+  in CONNECTING for 1000 ms (0 ms backoff)
 run
   should disconnect
 connect-failed
@@ -585,12 +600,12 @@ run
 
 # Second connection attempt fails after 1000 ms.
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (1000 ms backoff)
+  in CONNECTING for 0 ms (1000 ms backoff)
 timeout
   advance 1000 ms
 
 ### t=4000 ###
-  in CONNECT_IN_PROGRESS for 1000 ms (1000 ms backoff)
+  in CONNECTING for 1000 ms (1000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -608,28 +623,29 @@ run
 
 # Third connection attempt succeeds after 500 ms.
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (2000 ms backoff)
+  in CONNECTING for 0 ms (2000 ms backoff)
 advance 500
 
 ### t=6500 ###
-  in CONNECT_IN_PROGRESS for 500 ms (2000 ms backoff)
+  in CONNECTING for 500 ms (2000 ms backoff)
 run
 connected
   in ACTIVE for 0 ms (2000 ms backoff)
-  created 1000, last received 1000, last connected 6500
+  created 1000, last activity 1000, last connected 6500
   1 successful connections out of 3 attempts, seqno 1
-  connected (0 ms), total 0 ms connected
+  connected
+  last connected 0 ms ago, connected 0 ms total
 
 # Connection drops after another 250 ms.
 advance 250
 
 ### t=6750 ###
   in ACTIVE for 250 ms (2000 ms backoff)
-  connected (250 ms), total 250 ms connected
 disconnected
   in BACKOFF for 0 ms (4000 ms backoff)
   1 successful connections out of 3 attempts, seqno 2
-  not connected (0 ms), total 250 ms connected
+  disconnected
+  disconnected at 6750 ms (0 ms ago)
 run
 
 # Back off for 4000 ms.
@@ -638,15 +654,14 @@ timeout
 
 ### t=10750 ###
   in BACKOFF for 4000 ms (4000 ms backoff)
+  last connected 4250 ms ago, connected 250 ms total
 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
@@ -679,13 +694,13 @@ connected
 # Connection receives 3 chunks of data spaced 250 ms apart.
 advance 250
 run
-received
+activity
 advance 250
 run
-received
+activity
 advance 250
 run
-received
+activity
 
 # Connection drops.
 disconnected
@@ -694,8 +709,7 @@ run
 # Back off for 4000 ms.
 timeout
 run
-])
-AT_CHECK([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
@@ -704,13 +718,13 @@ enable
 run
   should connect
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (0 ms backoff)
+  in CONNECTING for 0 ms (0 ms backoff)
 run
 timeout
   advance 1000 ms
 
 ### t=2000 ###
-  in CONNECT_IN_PROGRESS for 1000 ms (0 ms backoff)
+  in CONNECTING for 1000 ms (0 ms backoff)
 run
   should disconnect
 connect-failed
@@ -728,12 +742,12 @@ run
 
 # Second connection attempt fails after 1000 ms.
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (1000 ms backoff)
+  in CONNECTING for 0 ms (1000 ms backoff)
 timeout
   advance 1000 ms
 
 ### t=4000 ###
-  in CONNECT_IN_PROGRESS for 1000 ms (1000 ms backoff)
+  in CONNECTING for 1000 ms (1000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -751,49 +765,48 @@ run
 
 # Third connection attempt succeeds after 500 ms.
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (2000 ms backoff)
+  in CONNECTING for 0 ms (2000 ms backoff)
 advance 500
 
 ### t=6500 ###
-  in CONNECT_IN_PROGRESS for 500 ms (2000 ms backoff)
+  in CONNECTING for 500 ms (2000 ms backoff)
 run
 connected
   in ACTIVE for 0 ms (2000 ms backoff)
-  created 1000, last received 1000, last connected 6500
+  created 1000, last activity 1000, last connected 6500
   1 successful connections out of 3 attempts, seqno 1
-  connected (0 ms), total 0 ms connected
+  connected
+  last connected 0 ms ago, connected 0 ms total
 
 # Connection receives 3 chunks of data spaced 250 ms apart.
 advance 250
 
 ### t=6750 ###
   in ACTIVE for 250 ms (2000 ms backoff)
-  connected (250 ms), total 250 ms connected
 run
-received
-  created 1000, last received 6750, last connected 6500
+activity
+  created 1000, last activity 6750, last connected 6500
 advance 250
 
 ### t=7000 ###
   in ACTIVE for 500 ms (2000 ms backoff)
-  connected (500 ms), total 500 ms connected
 run
-received
-  created 1000, last received 7000, last connected 6500
+activity
+  created 1000, last activity 7000, last connected 6500
 advance 250
 
 ### t=7250 ###
   in ACTIVE for 750 ms (2000 ms backoff)
-  connected (750 ms), total 750 ms connected
 run
-received
-  created 1000, last received 7250, last connected 6500
+activity
+  created 1000, last activity 7250, last connected 6500
 
 # Connection drops.
 disconnected
   in BACKOFF for 0 ms (4000 ms backoff)
   1 successful connections out of 3 attempts, seqno 2
-  not connected (0 ms), total 750 ms connected
+  disconnected
+  disconnected at 7250 ms (0 ms ago)
 run
 
 # Back off for 4000 ms.
@@ -802,15 +815,14 @@ timeout
 
 ### t=11250 ###
   in BACKOFF for 4000 ms (4000 ms backoff)
+  last connected 4750 ms ago, connected 750 ms total
 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
@@ -843,13 +855,13 @@ connected
 # Connection receives 3 chunks of data spaced 2000 ms apart.
 advance 2000
 run
-received
+activity
 advance 2000
 run
-received
+activity
 advance 2000
 run
-received
+activity
 
 # Connection drops.
 disconnected
@@ -858,8 +870,7 @@ run
 # Back off for 1000 ms.
 timeout
 run
-])
-AT_CHECK([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
@@ -868,13 +879,13 @@ enable
 run
   should connect
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (0 ms backoff)
+  in CONNECTING for 0 ms (0 ms backoff)
 run
 timeout
   advance 1000 ms
 
 ### t=2000 ###
-  in CONNECT_IN_PROGRESS for 1000 ms (0 ms backoff)
+  in CONNECTING for 1000 ms (0 ms backoff)
 run
   should disconnect
 connect-failed
@@ -892,12 +903,12 @@ run
 
 # Second connection attempt fails after 1000 ms.
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (1000 ms backoff)
+  in CONNECTING for 0 ms (1000 ms backoff)
 timeout
   advance 1000 ms
 
 ### t=4000 ###
-  in CONNECT_IN_PROGRESS for 1000 ms (1000 ms backoff)
+  in CONNECTING for 1000 ms (1000 ms backoff)
 run
   should disconnect
 connect-failed
@@ -915,49 +926,48 @@ run
 
 # Third connection attempt succeeds after 500 ms.
 connecting
-  in CONNECT_IN_PROGRESS for 0 ms (2000 ms backoff)
+  in CONNECTING for 0 ms (2000 ms backoff)
 advance 500
 
 ### t=6500 ###
-  in CONNECT_IN_PROGRESS for 500 ms (2000 ms backoff)
+  in CONNECTING for 500 ms (2000 ms backoff)
 run
 connected
   in ACTIVE for 0 ms (2000 ms backoff)
-  created 1000, last received 1000, last connected 6500
+  created 1000, last activity 1000, last connected 6500
   1 successful connections out of 3 attempts, seqno 1
-  connected (0 ms), total 0 ms connected
+  connected
+  last connected 0 ms ago, connected 0 ms total
 
 # Connection receives 3 chunks of data spaced 2000 ms apart.
 advance 2000
 
 ### t=8500 ###
   in ACTIVE for 2000 ms (2000 ms backoff)
-  connected (2000 ms), total 2000 ms connected
 run
-received
-  created 1000, last received 8500, last connected 6500
+activity
+  created 1000, last activity 8500, last connected 6500
 advance 2000
 
 ### t=10500 ###
   in ACTIVE for 4000 ms (2000 ms backoff)
-  connected (4000 ms), total 4000 ms connected
 run
-received
-  created 1000, last received 10500, last connected 6500
+activity
+  created 1000, last activity 10500, last connected 6500
 advance 2000
 
 ### t=12500 ###
   in ACTIVE for 6000 ms (2000 ms backoff)
-  connected (6000 ms), total 6000 ms connected
 run
-received
-  created 1000, last received 12500, last connected 6500
+activity
+  created 1000, last activity 12500, last connected 6500
 
 # Connection drops.
 disconnected
   in BACKOFF for 0 ms (1000 ms backoff)
   1 successful connections out of 3 attempts, seqno 2
-  not connected (0 ms), total 6000 ms connected
+  disconnected
+  disconnected at 12500 ms (0 ms ago)
 run
 
 # Back off for 1000 ms.
@@ -966,15 +976,14 @@ timeout
 
 ### t=13500 ###
   in BACKOFF for 1000 ms (1000 ms backoff)
+  last connected 7000 ms ago, connected 6000 ms total
 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
@@ -991,9 +1000,8 @@ connect-failed ECONNREFUSED
 # Back off for 2000 ms.
 run
 timeout
-])
-AT_CHECK([test-reconnect < input], [0], 
-  [### t=1000 ###
+],
+   [### t=1000 ###
 enable
   in BACKOFF for 0 ms (0 ms backoff)
 
@@ -1027,12 +1035,10 @@ timeout
 ### t=4000 ###
   in BACKOFF for 2000 ms (2000 ms backoff)
 ])
-AT_CLEANUP
 
 ######################################################################
-AT_SETUP([max-tries of 1 honored])
-AT_KEYWORDS([reconnect])
-AT_DATA([input], [set-max-tries 1
+RECONNECT_CHECK([max-tries of 1 honored],
+  [set-max-tries 1
 enable
 
 # Connection succeeds.
@@ -1047,8 +1053,7 @@ run
 timeout
 run
 disconnected
-])
-AT_CHECK([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 set-max-tries 1
   1 tries left
@@ -1061,8 +1066,10 @@ run
   should connect
 connected
   in ACTIVE for 0 ms (0 ms backoff)
+  created 1000, last activity 1000, last connected 1000
   1 successful connections out of 1 attempts, seqno 1
-  connected (0 ms), total 0 ms connected
+  connected
+  last connected 0 ms ago, connected 0 ms total
 
 # Send inactivity probe.
 timeout
@@ -1070,7 +1077,6 @@ timeout
 
 ### 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)
@@ -1081,25 +1087,22 @@ timeout
 
 ### 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
+  disconnected
+  disconnected at 11000 ms (0 ms ago)
 ])
-AT_CLEANUP
 
 ######################################################################
-AT_SETUP([max-tries of 0 honored])
-AT_KEYWORDS([reconnect])
-AT_DATA([input], [set-max-tries 0
+RECONNECT_CHECK([max-tries of 0 honored],
+  [set-max-tries 0
 enable
 run
 timeout
-])
-AT_CHECK([test-reconnect < input], [0], 
+],
   [### t=1000 ###
 set-max-tries 0
   0 tries left
@@ -1108,4 +1111,119 @@ run
 timeout
   no timeout
 ])
-AT_CLEANUP
+
+######################################################################
+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
+activity
+advance 1000
+activity
+
+# 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 activity 1000, last connected 2000
+  1 successful connections out of 1 attempts, seqno 1
+  connected
+  last connected 0 ms ago, connected 0 ms total
+activity
+  created 1000, last activity 2000, last connected 2000
+advance 1000
+
+### t=3000 ###
+  in ACTIVE for 1000 ms (1000 ms backoff)
+activity
+  created 1000, last activity 3000, last connected 2000
+
+# Connection times out.
+timeout
+  advance 5000 ms
+
+### t=8000 ###
+  in ACTIVE for 6000 ms (1000 ms backoff)
+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)
+run
+  should disconnect
+disconnected
+  in BACKOFF for 0 ms (0 ms backoff)
+  1 successful connections out of 1 attempts, seqno 2
+  disconnected
+  disconnected at 13000 ms (0 ms ago)
+
+# Start listening again.
+timeout
+  advance 0 ms
+run
+  should connect
+listening
+  in LISTENING for 0 ms (0 ms backoff)
+])