You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2015/07/29 17:54:32 UTC

[03/50] mochiweb commit: updated refs/heads/upstream to b66b68d

Avoid sleeping in the unittests.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/commit/3138381d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/tree/3138381d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/diff/3138381d

Branch: refs/heads/upstream
Commit: 3138381d3f7434a370a8eac9e9be93d055e8bd28
Parents: af7f519
Author: Shayan Pooya <sh...@chango.com>
Authored: Mon Mar 24 11:44:39 2014 -0400
Committer: Shayan Pooya <sh...@chango.com>
Committed: Mon Mar 24 11:59:29 2014 -0400

----------------------------------------------------------------------
 test/mochiweb_socket_server_tests.erl | 32 ++++++++++++------------------
 1 file changed, 13 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/3138381d/test/mochiweb_socket_server_tests.erl
----------------------------------------------------------------------
diff --git a/test/mochiweb_socket_server_tests.erl b/test/mochiweb_socket_server_tests.erl
index 6348d0f..0dad09d 100644
--- a/test/mochiweb_socket_server_tests.erl
+++ b/test/mochiweb_socket_server_tests.erl
@@ -76,11 +76,13 @@ test_basic_accept(Max, PoolSize, NumClients, ReportTo) ->
                   {send, Data, Tester}, {recv, size(Data), Timeout, Tester},
                   {close_sock}, {send_msg, done, Tester}],
     start_client_conns(Port, NumClients, fun client_fun/2, ClientCmds, Tester),
-    % Wait a bit for the connections to complete.
-    timer:sleep(2500),
+
+    EventCount = min(NumClients, max(Max, PoolSize)),
+
     ConnectLoop =
         fun (Loop, Connected, Accepted, Errors) ->
-                case (length(Connected) + Errors >= NumClients) of
+                case (length(Accepted) + Errors >= EventCount
+                        andalso length(Connected) + Errors >= NumClients) of
                     true -> {Connected, Accepted};
                     false ->
                         receive
@@ -113,29 +115,21 @@ test_basic_accept(Max, PoolSize, NumClients, ReportTo) ->
         end,
     ok = WaitLoop(WaitLoop, []),
 
-    % Wait a little for the server side connections to get their
-    % socket close notifications.
-    timer:sleep(1500),
-
-    ActiveAtEnd = mochiweb_socket_server:get(Server, active_sockets),
-    WaitingAtEnd = mochiweb_socket_server:get(Server, waiting_acceptors),
     mochiweb_socket_server:stop(Server),
 
     ReportTo ! {result, {length(Accepted),
-                         ActiveAfterConnect, WaitingAfterConnect,
-                         ActiveAtEnd, WaitingAtEnd}}.
+                         ActiveAfterConnect, WaitingAfterConnect}}.
 
 normal_acceptor_test_fun() ->
     %        {Max, PoolSize, NumClients,
     %         {ExpectedAccepts,
-    %          ExpectedActiveAfterConnect, ExpectedWaitingAfterConnect,
-    %          ExpectedActiveAtEnd, ExpectedWaitingAtEnd}}
-    Tests = [{3, 1, 1,   {1,   1, 1,   0, 1}},
-             {3, 1, 2,   {2,   2, 1,   0, 1}},
-             {3, 1, 3,   {3,   3, 0,   0, 1}},
-             {3, 3, 3,   {3,   3, 0,   0, 3}},
-             {1, 3, 3,   {3,   3, 0,   0, 3}}, % Max is overridden to PoolSize
-             {3, 2, 10,  {3,   3, 0,   0, 2}}
+    %          ExpectedActiveAfterConnect, ExpectedWaitingAfterConnect}
+    Tests = [{3, 1, 1,   {1,   1, 1}},
+             {3, 1, 2,   {2,   2, 1}},
+             {3, 1, 3,   {3,   3, 0}},
+             {3, 3, 3,   {3,   3, 0}},
+             {1, 3, 3,   {3,   3, 0}}, % Max is overridden to PoolSize
+             {3, 2, 6,  {3,   3, 0}}
             ],
     [fun () ->
              Self = self(),