DHCP-test: more robust sleep check 84/17084/2
authorNeale Ranns <nranns@cisco.com>
Fri, 25 Jan 2019 14:37:15 +0000 (06:37 -0800)
committerNeale Ranns <nranns@cisco.com>
Thu, 31 Jan 2019 09:19:52 +0000 (09:19 +0000)
Change-Id: I48c382797239dc305e01cc35124140d6ce16149a
Signed-off-by: Neale Ranns <nranns@cisco.com>
test/test_dhcp.py

index 833ee00..d1af9fd 100644 (file)
@@ -360,6 +360,16 @@ class TestDHCP(VppTestCase):
         # not sure why this is not decoding
         # adv = pkt[DHCP6_Advertise]
 
+    def wait_for_no_route(self, address, length,
+                          n_tries=50, s_time=1):
+        while (n_tries):
+            if not find_route(self, address, length):
+                return True
+            n_tries = n_tries - 1
+            self.sleep(s_time)
+
+        return False
+
     def test_dhcp_proxy(self):
         """ DHCPv4 Proxy """
 
@@ -1535,15 +1545,10 @@ class TestDHCP(VppTestCase):
                                       is_add=0)
 
         #
-        # Sleep for the lease time
-        #
-        self.sleep(lease_time+1)
-
+        # the route should be gone after the lease expires
         #
-        # And now the route should be gone
-        #
-        self.assertFalse(find_route(self, self.pg3.local_ip4, 32))
-        self.assertFalse(find_route(self, self.pg3.local_ip4, 24))
+        self.assertTrue(self.wait_for_no_route(self.pg3.local_ip4, 32))
+        self.assertTrue(self.wait_for_no_route(self.pg3.local_ip4, 24))
 
         #
         # remove the DHCP config