You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2015/04/03 19:29:40 UTC
mesos git commit: Replaced busy loop on ready file with a more
relaxed loop in port mapping tests.
Repository: mesos
Updated Branches:
refs/heads/master 0e4f6564a -> eb4b19ba4
Replaced busy loop on ready file with a more relaxed loop in port
mapping tests.
Review: https://reviews.apache.org/r/32653
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/eb4b19ba
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/eb4b19ba
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/eb4b19ba
Branch: refs/heads/master
Commit: eb4b19ba45c10b985004d3f8d0a1bf01fc047ad7
Parents: 0e4f656
Author: Paul Brett <pa...@twopensource.com>
Authored: Fri Apr 3 10:24:04 2015 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Fri Apr 3 10:29:28 2015 -0700
----------------------------------------------------------------------
src/tests/port_mapping_tests.cpp | 40 +++++++++++++++++++++++++++--------
1 file changed, 31 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/eb4b19ba/src/tests/port_mapping_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/port_mapping_tests.cpp b/src/tests/port_mapping_tests.cpp
index fbb9414..58709b5 100644
--- a/src/tests/port_mapping_tests.cpp
+++ b/src/tests/port_mapping_tests.cpp
@@ -33,6 +33,7 @@
#include <stout/json.hpp>
#include <stout/mac.hpp>
#include <stout/net.hpp>
+#include <stout/stopwatch.hpp>
#include <stout/os/stat.hpp>
#include <stout/os/exists.hpp>
@@ -313,7 +314,6 @@ protected:
return pid;
}
-
JSON::Object statisticsHelper(
pid_t pid,
bool enable_summary,
@@ -388,6 +388,28 @@ protected:
};
+// Wait up to timeout seconds for a file to be created. If timeout is
+// zero, then wait indefinitely. Return true if file exists.
+// TODO(pbrett): Consider generalizing this function and moving it to a
+// common header.
+static bool waitForFileCreation(
+ const string& path,
+ const Duration& duration = Seconds(60))
+{
+ Stopwatch timer;
+ timer.start();
+
+ while (!os::exists(path)) {
+ if ((duration > Duration::zero()) && (timer.elapsed() > duration))
+ break;
+
+ os::sleep(Milliseconds(50));
+ }
+
+ return os::exists(path);
+}
+
+
// This test uses 2 containers: one listens to 'port' and 'errorPort'
// and writes data received to files; the other container attemptes to
// connect to the previous container using 'port' and
@@ -462,7 +484,7 @@ TEST_F(PortMappingIsolatorTest, ROOT_ContainerToContainerTCPTest)
::close(pipes[1]);
// Wait for the command to start.
- while (!os::exists(container1Ready));
+ ASSERT_TRUE(waitForFileCreation(container1Ready));
ContainerID containerId2;
containerId2.set_value("container2");
@@ -520,7 +542,7 @@ TEST_F(PortMappingIsolatorTest, ROOT_ContainerToContainerTCPTest)
::close(pipes[1]);
// Wait for the command to start.
- while (!os::exists(container2Ready));
+ ASSERT_TRUE(waitForFileCreation(container2Ready));
// Wait for the command to complete.
AWAIT_READY(status1);
@@ -613,7 +635,7 @@ TEST_F(PortMappingIsolatorTest, ROOT_ContainerToContainerUDPTest)
::close(pipes[1]);
// Wait for the command to start.
- while (!os::exists(container1Ready));
+ ASSERT_TRUE(waitForFileCreation(container1Ready));
ContainerID containerId2;
containerId2.set_value("container2");
@@ -672,7 +694,7 @@ TEST_F(PortMappingIsolatorTest, ROOT_ContainerToContainerUDPTest)
::close(pipes[1]);
// Wait for the command to start.
- while (!os::exists(container2Ready));
+ ASSERT_TRUE(waitForFileCreation(container2Ready));
// Wait for the command to complete.
AWAIT_READY(status1);
@@ -767,7 +789,7 @@ TEST_F(PortMappingIsolatorTest, ROOT_HostToContainerUDPTest)
::close(pipes[1]);
// Wait for the command to start.
- while (!os::exists(container1Ready));
+ ASSERT_TRUE(waitForFileCreation(container1Ready));
// Send to 'localhost' and 'port'.
ASSERT_SOME_EQ(0, os::shell(
@@ -883,7 +905,7 @@ TEST_F(PortMappingIsolatorTest, ROOT_HostToContainerTCPTest)
::close(pipes[1]);
// Wait for the command to start.
- while (!os::exists(container1Ready));
+ ASSERT_TRUE(waitForFileCreation(container1Ready));
// Send to 'localhost' and 'port'.
ASSERT_SOME_EQ(0, os::shell(
@@ -1453,7 +1475,7 @@ TEST_F(PortMappingIsolatorTest, ROOT_SmallEgressLimitTest)
::close(pipes[1]);
// Wait for the command to finish.
- while (!os::exists(container1Ready));
+ ASSERT_TRUE(waitForFileCreation(container1Ready));
Try<string> read = os::read(transmissionTime);
CHECK_SOME(read);
@@ -1647,7 +1669,7 @@ TEST_F(PortMappingIsolatorTest, ROOT_PortMappingStatisticsTest)
ASSERT_TRUE(!HasTCPSocketsCount(object) && !HasTCPSocketsRTT(object));
// Wait for the command to finish.
- while (!os::exists(container1Ready));
+ ASSERT_TRUE(waitForFileCreation(container1Ready));
// Make sure the nc server exits normally.
Future<Option<int> > status = s.get().status();