Merge lp:~stewart/galera/bug907623 into lp:galera/2.x

Proposed by Stewart Smith
Status: Merged
Approved by: Alex Yurchenko
Approved revision: 109
Merge reported by: Alex Yurchenko
Merged at revision: not available
Proposed branch: lp:~stewart/galera/bug907623
Merge into: lp:galera/2.x
Diff against target: 187 lines (+50/-15)
3 files modified
galerautils/src/gu_network.cpp (+14/-1)
galerautils/tests/gu_net_test.cpp (+34/-13)
gcomm/test/check_util.cpp (+2/-1)
To merge this branch: bzr merge lp:~stewart/galera/bug907623
Reviewer Review Type Date Requested Status
Alex Yurchenko Approve
Review via email: mp+87434@code.launchpad.net

Description of the change

This branch enables the test suite to be run multiple times concurrently on the same machine.

Prior to this branch being merged, if you simply built Galera by using "scons" or build script in two completely different directories on the same machine, you could get test failures due to the test suite trying to open the same TCP port.

This branch changes the test suite to instead of having hard coded port numbers, to use Operating System assigned ones. This means you can have as many concurrent builds on a single machine as you have free TCP ports.

You get an OS assigned port number simply by binding to port 0 instead of 10001 or some such number. You then just ask the OS for what port number it gave you.

The changes are pretty minor to get there, and it *really* helps when you're running Continuous Integration.

To post a comment you must log in.
Revision history for this message
Alex Yurchenko (ayurchen) wrote :

gu::Network is deprecated in favour of asio and should be removed from the code.

review: Disapprove
Revision history for this message
Stewart Smith (stewart) wrote :

I do not think that is a valid reason to reject this. This patch is a simple fix for a current problem, it is not a refactor of existing code (and that should be a separate patch). Rewriting large swaths of code just so that you can compile simultaneously doesn't really seem like the right way to do it - and certainly makes it harder to test any refactored code.

I really hope that you reconsider this one, as without a patch like this it makes it really hard for us to do further build and test.

Revision history for this message
Alex Yurchenko (ayurchen) wrote :

I have disabled gu::Network unit tests, so they should not interfer with the build anymore. Is there still a problem?

If you find that disabling unit tests is not enough and you still wish us to incorporate this patch, please explicitly assign the copyright to Codership Oy. (Which I'm not sure how to do with LP, honestly. Perhaps in the comments?)

review: Needs Resubmitting
Revision history for this message
Stewart Smith (stewart) wrote :

It looks like check_util is still run, which also deals with a TCP port. So it probably is a good idea to merge this branch.

I'm not sure what you need for copyright assignment - but I hereby assign Codership Oy all rights to the code in this merge request.

Revision history for this message
Alex Yurchenko (ayurchen) wrote :

Yes, our bad. We merged the relevant part of the patch in revno 107, please try if that works.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'galerautils/src/gu_network.cpp'
--- galerautils/src/gu_network.cpp 2011-02-01 19:13:25 +0000
+++ galerautils/src/gu_network.cpp 2012-01-04 05:59:23 +0000
@@ -441,8 +441,21 @@
441 }441 }
442442
443 set_opt(this, ai, ::get_opt(uri));443 set_opt(this, ai, ::get_opt(uri));
444 listener_ai = new Addrinfo(ai);444
445 Sockaddr local_sa(sa);
446 struct sockaddr *servaddr= &(local_sa.get_sockaddr());
447 socklen_t sock_len= local_sa.get_sockaddr_len();
448
449 if (::getsockname(fd, servaddr, &sock_len) == -1)
450 {
451 set_state(S_FAILED, errno);
452 gu_throw_error(errno);
453 }
454
455 listener_ai = new Addrinfo(ai, local_sa);
445 set_state(S_LISTENING);456 set_state(S_LISTENING);
457
458 local_addr = listener_ai->to_string();
446}459}
447460
448gu::net::Socket* gu::net::Socket::accept()461gu::net::Socket* gu::net::Socket::accept()
449462
=== modified file 'galerautils/tests/gu_net_test.cpp'
--- galerautils/tests/gu_net_test.cpp 2011-02-01 19:13:25 +0000
+++ galerautils/tests/gu_net_test.cpp 2012-01-04 05:59:23 +0000
@@ -197,7 +197,7 @@
197{197{
198 log_info << "START";198 log_info << "START";
199 Network net;199 Network net;
200 Socket* listener = net.listen("tcp://localhost:2112");200 Socket* listener = net.listen("tcp://localhost:0");
201 listener->close();201 listener->close();
202 delete listener;202 delete listener;
203}203}
@@ -301,16 +301,19 @@
301 gu_log_max_level = GU_LOG_DEBUG;301 gu_log_max_level = GU_LOG_DEBUG;
302 log_info << "START";302 log_info << "START";
303 Network* net = new Network;303 Network* net = new Network;
304 Socket* listener = net->listen("tcp://localhost:2112");304 Socket* listener = net->listen("tcp://localhost:0");
305305
306 log_info << "listener " << listener->get_local_addr();306 log_info << "listener " << listener->get_local_addr();
307307
308 std::string uri_str;
309 uri_str= listener->get_local_addr();
310
308 listener_thd_args args = {net, 2, 0, 0};311 listener_thd_args args = {net, 2, 0, 0};
309 pthread_t th;312 pthread_t th;
310 pthread_create(&th, 0, &listener_thd, &args);313 pthread_create(&th, 0, &listener_thd, &args);
311314
312 Network* net2 = new Network;315 Network* net2 = new Network;
313 Socket* conn = net2->connect("tcp://localhost:2112");316 Socket* conn = net2->connect(uri_str);
314317
315 fail_unless(conn != 0);318 fail_unless(conn != 0);
316 fail_unless(conn->get_state() == Socket::S_CONNECTED);319 fail_unless(conn->get_state() == Socket::S_CONNECTED);
@@ -318,7 +321,7 @@
318 log_info << "connected remote " << conn->get_remote_addr();321 log_info << "connected remote " << conn->get_remote_addr();
319 log_info << "connected local " << conn->get_local_addr();322 log_info << "connected local " << conn->get_local_addr();
320323
321 Socket* conn2 = net2->connect("tcp://localhost:2112");324 Socket* conn2 = net2->connect(uri_str);
322 fail_unless(conn2 != 0);325 fail_unless(conn2 != 0);
323 fail_unless(conn2->get_state() == Socket::S_CONNECTED);326 fail_unless(conn2->get_state() == Socket::S_CONNECTED);
324327
@@ -357,18 +360,21 @@
357 }360 }
358361
359 Network* net = new Network;362 Network* net = new Network;
360 Socket* listener = net->listen("tcp://localhost:2112");363 Socket* listener = net->listen("tcp://localhost:0");
364
365 std::string uri_str(listener->get_local_addr());
366
361 listener_thd_args args = {net, 2, buf, bufsize};367 listener_thd_args args = {net, 2, buf, bufsize};
362 pthread_t th;368 pthread_t th;
363 pthread_create(&th, 0, &listener_thd, &args);369 pthread_create(&th, 0, &listener_thd, &args);
364370
365 Network* net2 = new Network;371 Network* net2 = new Network;
366 Socket* conn = net2->connect("tcp://localhost:2112");372 Socket* conn = net2->connect(uri_str);
367373
368 fail_unless(conn != 0);374 fail_unless(conn != 0);
369 fail_unless(conn->get_state() == Socket::S_CONNECTED);375 fail_unless(conn->get_state() == Socket::S_CONNECTED);
370376
371 Socket* conn2 = net2->connect("tcp://localhost:2112");377 Socket* conn2 = net2->connect(uri_str);
372 fail_unless(conn2 != 0);378 fail_unless(conn2 != 0);
373 fail_unless(conn2->get_state() == Socket::S_CONNECTED);379 fail_unless(conn2->get_state() == Socket::S_CONNECTED);
374380
@@ -486,7 +492,8 @@
486}492}
487END_TEST493END_TEST
488494
489static void make_connections(Network& net, 495static void make_connections(std::string uri_str,
496 Network& net,
490 vector<Socket*>& cl,497 vector<Socket*>& cl,
491 vector<Socket*>& sr,498 vector<Socket*>& sr,
492 size_t n)499 size_t n)
@@ -495,7 +502,7 @@
495 sr.resize(n);502 sr.resize(n);
496 for (size_t i = 0; i < n; ++i)503 for (size_t i = 0; i < n; ++i)
497 {504 {
498 cl[i] = net.connect("tcp://localhost:2112?socket.non_blocking=1");505 cl[i] = net.connect(uri_str);
499 }506 }
500 size_t sr_cnt = 0;507 size_t sr_cnt = 0;
501 size_t cl_cnt = 0;508 size_t cl_cnt = 0;
@@ -555,12 +562,16 @@
555 log_info << "START";562 log_info << "START";
556 Network net;563 Network net;
557564
558 Socket* listener = net.listen("tcp://localhost:2112?socket.non_blocking=1");565 Socket* listener = net.listen("tcp://localhost:0?socket.non_blocking=1");
566 std::string uri_str(listener->get_local_addr());
567
568 uri_str.append("?socket.non_blocking=1");
569
559 log_info << "listener: " << *listener;570 log_info << "listener: " << *listener;
560 vector<Socket*> cl;571 vector<Socket*> cl;
561 vector<Socket*> sr;572 vector<Socket*> sr;
562 gu_log_max_level = GU_LOG_DEBUG;573 gu_log_max_level = GU_LOG_DEBUG;
563 make_connections(net, cl, sr, 3);574 make_connections(uri_str, net, cl, sr, 3);
564575
565 close_connections(net, cl, sr);576 close_connections(net, cl, sr);
566577
@@ -666,6 +677,8 @@
666677
667public:678public:
668679
680 std::string get_url() { return listener->get_local_addr(); }
681
669 void connect(const string& url)682 void connect(const string& url)
670 {683 {
671 send_sock = net.connect(url);684 send_sock = net.connect(url);
@@ -782,8 +795,12 @@
782START_TEST(test_net_consumer)795START_TEST(test_net_consumer)
783{796{
784 log_info << "START";797 log_info << "START";
785 string url("tcp://localhost:2112?socket.non_blocking=1");798 string url("tcp://localhost:0?socket.non_blocking=1");
786 NetConsumer cons(url);799 NetConsumer cons(url);
800
801 url= cons.get_url();
802 url.append("?socket.non_blocking=1");
803
787 cons.connect(url);804 cons.connect(url);
788805
789 cons.start();806 cons.start();
@@ -853,8 +870,12 @@
853START_TEST(test_net_consumer_nto1)870START_TEST(test_net_consumer_nto1)
854{871{
855 log_info << "START";872 log_info << "START";
856 string url("tcp://localhost:2112?socket.non_blocking=1");873 string url("tcp://localhost:0?socket.non_blocking=1");
857 NetConsumer cons(url);874 NetConsumer cons(url);
875
876 url= cons.get_url();
877 url.append("?socket.non_blocking=1");
878
858 cons.connect(url);879 cons.connect(url);
859880
860 cons.start();881 cons.start();
861882
=== modified file 'gcomm/test/check_util.cpp'
--- gcomm/test/check_util.cpp 2011-02-01 19:13:25 +0000
+++ gcomm/test/check_util.cpp 2012-01-04 05:59:23 +0000
@@ -58,10 +58,11 @@
58{58{
59 gu::Config conf;59 gu::Config conf;
60 AsioProtonet pn(conf);60 AsioProtonet pn(conf);
61 const string uri_str("tcp://localhost:10001");61 string uri_str("tcp://localhost:0");
6262
63 Acceptor* acc = pn.acceptor(uri_str);63 Acceptor* acc = pn.acceptor(uri_str);
64 acc->listen(uri_str);64 acc->listen(uri_str);
65 uri_str = acc->listen_addr();
6566
66 SocketPtr cl = pn.socket(uri_str);67 SocketPtr cl = pn.socket(uri_str);
67 cl->connect(uri_str);68 cl->connect(uri_str);

Subscribers

People subscribed via source and target branches

to all changes: