s3: torture - Fix racy assumption in original messaging test.
authorJeremy Allison <jra@samba.org>
Tue, 22 Apr 2014 23:07:18 +0000 (16:07 -0700)
committerJeremy Allison <jra@samba.org>
Wed, 23 Apr 2014 22:50:55 +0000 (00:50 +0200)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: "Stefan (metze) Metzmacher" <metze@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Apr 24 00:50:55 CEST 2014 on sn-devel-104

source3/torture/msgtest.c

index 32f4b04cf0c096da76490cba7c11d65def9b9d00..07a7b6dbe868e3cd4a7a86c8826af9612dec64e5 100644 (file)
@@ -85,7 +85,7 @@ static void pong_message(struct messaging_context *msg_ctx,
                }
        }
 
-       /* Now test that the duplicate filtering code works. */
+       /* Ensure all messages get through to ourselves. */
        pong_count = 0;
 
        strlcpy(buf, "1234567890", sizeof(buf));
@@ -97,15 +97,25 @@ static void pong_message(struct messaging_context *msg_ctx,
                                   MSG_PING,(uint8 *)buf, 11);
        }
 
-       for (i=0;i<n;i++) {
+       /*
+        * We have to loop at least 2 times for
+        * each message as local ping messages are
+        * handled by an immediate callback, that
+        * has to be dispatched, which sends a pong
+        * message, which also has to be dispatched.
+        * Above we sent 2*n messages, which means
+        * we have to dispatch 4*n times.
+        */
+
+       while (pong_count < n*2) {
                ret = tevent_loop_once(evt_ctx);
                if (ret != 0) {
                        break;
                }
        }
 
-       if (pong_count != 2) {
-               fprintf(stderr, "Duplicate filter failed (%d).\n", pong_count);
+       if (pong_count != 2*n) {
+               fprintf(stderr, "Message count failed (%d).\n", pong_count);
        }
 
        /* Speed testing */