Nir Soffer has uploaded a new change for review.

Change subject: tests: Fix race in protocoldetector tests
......................................................................

tests: Fix race in protocoldetector tests

To test removal of stale connections, we were waiting 2 cleanup
intervals on the client side, to make sure that the server would wake up
and remove the our stale connection.

However, since the server runs in a separate thread, and we have no way
to synchronize with it, it was possible that the server did not wake up
yet when the client woke up and try to send a message. This caused
test_reject_very_slow_client_concurrency() to fail from time to time.

Now we are waiting little more than two internals, so the server always
wakes up before the client and remove the stale connection.

Change-Id: Ib78d48de2521bd63cf270d613786b13e20846107
Signed-off-by: Nir Soffer <[email protected]>
---
M tests/protocoldetectorTests.py
1 file changed, 9 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/09/37009/1

diff --git a/tests/protocoldetectorTests.py b/tests/protocoldetectorTests.py
index a1231d1..6109113 100644
--- a/tests/protocoldetectorTests.py
+++ b/tests/protocoldetectorTests.py
@@ -87,6 +87,8 @@
 class AcceptorTests(VdsmTestCase):
 
     TIMEOUT = 2.0
+    GRACETIME = 0.2
+    CLEANUP_INTERVAL = 1.0
     CONCURRENCY = 5
     PERMUTATIONS = ((False,), (True,))
     SSLCTX = sslutils.SSLContext(CRT_FILE, KEY_FILE, ca_cert=CRT_FILE)
@@ -170,14 +172,18 @@
 
     def check_slow_client(self, use_ssl):
         with self.connect(use_ssl) as client:
-            time.sleep(self.acceptor.CLEANUP_INTERVAL - 0.2)
+            time.sleep(self.CLEANUP_INTERVAL - self.GRACETIME)
             data = "echo let me in\n"
             client.sendall(data)
             self.assertEqual(client.recv(self.BUFSIZE), data)
 
     def check_very_slow_client(self, use_ssl):
         with self.connect(use_ssl) as client:
-            time.sleep(self.acceptor.CLEANUP_INTERVAL * 2)
+            # We must wait until the acceptor wakes up twice to make sure our
+            # connection is stale and will be removed. Since the acceptor is
+            # running on another thread and we don't have any wayt ot
+            # synchronize with it, we must wait little more then two intervals.
+            time.sleep(self.CLEANUP_INTERVAL * 2 + self.GRACETIME)
             client.sendall("echo too slow probably\n")
             self.check_disconnected(client)
 
@@ -194,7 +200,7 @@
     def start_acceptor(self, use_ssl):
         self.acceptor = protocoldetector.MultiProtocolAcceptor(
             '127.0.0.1', 0, sslctx=self.SSLCTX if use_ssl else None)
-        self.acceptor.CLEANUP_INTERVAL = 1
+        self.acceptor.CLEANUP_INTERVAL = self.CLEANUP_INTERVAL
         self.acceptor.add_detector(Echo())
         self.acceptor.add_detector(Uppercase())
         self.acceptor_address = self.acceptor._socket.getsockname()


-- 
To view, visit http://gerrit.ovirt.org/37009
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib78d48de2521bd63cf270d613786b13e20846107
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to