From f98fbd5ad8c2f4d4a652dda45b4a2dfd1caa21ec Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Tue, 19 Nov 2013 16:51:06 +0100 Subject: [PATCH 1/2] Fixed test_many_sockets * failed on systems where process could not allocate 1024 sockets by default * include path for platform.hpp was wrong; fixed it --- tests/test_many_sockets.cpp | 75 ++++++++++++++++--------------------- tests/testutil.hpp | 2 +- 2 files changed, 33 insertions(+), 44 deletions(-) diff --git a/tests/test_many_sockets.cpp b/tests/test_many_sockets.cpp index d2c3f4f6..e98a030d 100644 --- a/tests/test_many_sockets.cpp +++ b/tests/test_many_sockets.cpp @@ -23,76 +23,65 @@ #include #include - void test_system_max () { // Keep allocating sockets until we run out of system resources - const int no_of_sockets = 2 * 65536; - void *ctx = zmq_ctx_new(); - zmq_ctx_set(ctx, ZMQ_MAX_SOCKETS, no_of_sockets); - std::vector sockets; + void *ctx = zmq_ctx_new (); + zmq_ctx_set (ctx, ZMQ_MAX_SOCKETS, no_of_sockets); + std::vector sockets; - while (true) - { - void *socket = zmq_socket(ctx, ZMQ_PAIR); + while (true) { + void *socket = zmq_socket (ctx, ZMQ_PAIR); if (!socket) break; - - sockets.push_back(socket); + sockets.push_back (socket); } + assert ((int) sockets.size () < no_of_sockets); - assert((int)sockets.size() < no_of_sockets); - - // System is out of resources, further calls to zmq_socket should return NULL. - for (unsigned int i = 0; i < 10; ++i) - { - void *socket = zmq_socket(ctx, ZMQ_PAIR); - assert(socket == NULL); + // System is out of resources, further calls to zmq_socket should return NULL + for (unsigned int i = 0; i < 10; ++i) { + void *socket = zmq_socket (ctx, ZMQ_PAIR); + assert (socket == NULL); } - // Clean up. - for (unsigned int i = 0; i < sockets.size(); ++i) - zmq_close(sockets[i]); + for (unsigned int i = 0; i < sockets.size (); ++i) + zmq_close (sockets [i]); - zmq_ctx_destroy(ctx); + zmq_ctx_destroy (ctx); } void test_zmq_default_max () { - // Keep allocating sockets until we hit the default zeromq limit - - void *ctx = zmq_ctx_new(); + // Keep allocating sockets until we hit the default limit + void *ctx = zmq_ctx_new (); std::vector sockets; - while (true) - { - void *socket = zmq_socket(ctx, ZMQ_PAIR); + while (true) { + void *socket = zmq_socket (ctx, ZMQ_PAIR); if (!socket) break; + sockets.push_back (socket); + } + // We may stop sooner if system has fewer available sockets + assert (sockets.size () <= ZMQ_MAX_SOCKETS_DFLT); - sockets.push_back(socket); + // Further calls to zmq_socket should return NULL + for (unsigned int i = 0; i < 10; ++i) { + void *socket = zmq_socket (ctx, ZMQ_PAIR); + assert (socket == NULL); } - assert(sockets.size() == ZMQ_MAX_SOCKETS_DFLT); + // Clean up + for (unsigned int i = 0; i < sockets.size (); ++i) + zmq_close (sockets [i]); - // At zeromq max, further calls to zmq_socket should return NULL. - for (unsigned int i = 0; i < 10; ++i) - { - void *socket = zmq_socket(ctx, ZMQ_PAIR); - assert(socket == NULL); - } - - // Clean up. - for (unsigned int i = 0; i < sockets.size(); ++i) - zmq_close(sockets[i]); - - zmq_ctx_destroy(ctx); + zmq_ctx_destroy (ctx); } -int main(void) +int main (void) { - setup_test_environment(); + setup_test_environment (); test_system_max (); test_zmq_default_max (); diff --git a/tests/testutil.hpp b/tests/testutil.hpp index 31db1e40..efb2a43d 100644 --- a/tests/testutil.hpp +++ b/tests/testutil.hpp @@ -22,7 +22,7 @@ #include "../include/zmq.h" #include "../include/zmq_utils.h" -#include "platform.hpp" +#include "../src/platform.hpp" // This defines the settle time used in tests; raise this if we // get test failures on slower systems due to binds/connects not From 4d22d456a91e649de39a7ad9e326d26585c6857b Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Tue, 19 Nov 2013 17:11:15 +0100 Subject: [PATCH 2/2] Reverting path change on platform.hpp, this broke some builds --- tests/testutil.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testutil.hpp b/tests/testutil.hpp index efb2a43d..31db1e40 100644 --- a/tests/testutil.hpp +++ b/tests/testutil.hpp @@ -22,7 +22,7 @@ #include "../include/zmq.h" #include "../include/zmq_utils.h" -#include "../src/platform.hpp" +#include "platform.hpp" // This defines the settle time used in tests; raise this if we // get test failures on slower systems due to binds/connects not