From 7b3e6cb2472f6e69fcfce05f5e6a5a0ecd144f47 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 14 Aug 2019 14:48:29 +0200 Subject: [PATCH] Gracefully handle the mplexer test pipe having only room for one --- pdns/test-mplexer.cc | 56 ++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/pdns/test-mplexer.cc b/pdns/test-mplexer.cc index 5a3269f559..f01500b6d1 100644 --- a/pdns/test-mplexer.cc +++ b/pdns/test-mplexer.cc @@ -122,35 +122,41 @@ BOOST_AUTO_TEST_CASE(test_MPlexer) { &ttd); /* both should be available */ + readCBCalled = false; + writeCBCalled = false; readyFDs.clear(); + mplexer->getAvailableFDs(readyFDs, 0); - if (readyFDs.size() == 1) { - /* something is wrong, we need some debug infos */ - cerr<<"FDMultiPlexer implementation is "<getName()<getWatchedFDCount(false)<<" FDs for read and "<getWatchedFDCount(true)<<" for write"<run(&now, 100); + BOOST_CHECK_EQUAL(ready, 2); + } + else if (readyFDs.size() == 1) { + /* under high pressure (lots of existing pipes on the system, for example, + the pipe might only have room for one 'buffer' and will not be writable + after our write of 1 byte, we need to read it so that the pipe becomes + writable again */ + /* make sure the pipe is readable, otherwise something is off */ + BOOST_REQUIRE_EQUAL(readyFDs.at(0), pipes[0]); + ready = mplexer->run(&now, 100); + BOOST_CHECK_EQUAL(ready, 1); + BOOST_CHECK_EQUAL(readCBCalled, true); + BOOST_CHECK_EQUAL(writeCBCalled, false); + char buffer[1]; + ssize_t got = read(pipes[0], &buffer[0], sizeof(buffer)); + BOOST_CHECK_EQUAL(got, 1); + + /* ok, the pipe should be writable now, but not readable */ + readyFDs.clear(); + mplexer->getAvailableFDs(readyFDs, 0); + BOOST_CHECK_EQUAL(readyFDs.size(), 1); + BOOST_REQUIRE_EQUAL(readyFDs.at(0), pipes[1]); + + ready = mplexer->run(&now, 100); + BOOST_CHECK_EQUAL(ready, 1); } - BOOST_CHECK_EQUAL(readyFDs.size(), 2); - readCBCalled = false; - writeCBCalled = false; - ready = mplexer->run(&now, 100); - BOOST_CHECK_EQUAL(ready, 2); BOOST_CHECK_EQUAL(readCBCalled, true); BOOST_CHECK_EQUAL(writeCBCalled, true); -- 2.47.2