summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/linger.cpp4
-rw-r--r--tests/polltimeo.cpp8
-rw-r--r--tests/testutil.hpp6
-rw-r--r--tests/timeo.cpp8
4 files changed, 11 insertions, 15 deletions
diff --git a/tests/linger.cpp b/tests/linger.cpp
index 42dfda0..fec0f72 100644
--- a/tests/linger.cpp
+++ b/tests/linger.cpp
@@ -52,9 +52,7 @@ int XS_TEST_MAIN ()
rc = xs_term (ctx);
assert (rc == 0);
int ms = (int) xs_stopwatch_stop (watch) / 1000;
-#if !defined _WIN32 || !defined _DEBUG
- assert (ms > 50 && ms < 150);
-#endif
+ time_assert (ms, linger);
return 0;
}
diff --git a/tests/polltimeo.cpp b/tests/polltimeo.cpp
index 73d7f53..ca88393 100644
--- a/tests/polltimeo.cpp
+++ b/tests/polltimeo.cpp
@@ -58,9 +58,7 @@ int XS_TEST_MAIN ()
rc = xs_poll (&pi, 1, 500);
assert (rc == 0);
unsigned long elapsed = xs_stopwatch_stop (watch) / 1000;
-#if !defined _WIN32 || !defined _DEBUG
- assert (elapsed > 440 && elapsed < 550);
-#endif
+ time_assert (elapsed, 500);
// Check whether connection during the wait doesn't distort the timeout.
void *thread = thread_create (polltimeo_worker, ctx);
@@ -69,9 +67,7 @@ int XS_TEST_MAIN ()
rc = xs_poll (&pi, 1, 2000);
assert (rc == 0);
elapsed = xs_stopwatch_stop (watch) / 1000;
-#if !defined _WIN32 || !defined _DEBUG
- assert (elapsed > 1900 && elapsed < 2100);
-#endif
+ time_assert (elapsed, 2000);
thread_join (thread);
// Clean-up.
diff --git a/tests/testutil.hpp b/tests/testutil.hpp
index 4e0287a..58f1afd 100644
--- a/tests/testutil.hpp
+++ b/tests/testutil.hpp
@@ -173,4 +173,10 @@ inline void bounce (void *sb, void *sc)
assert (memcmp (buf2, content, 32) == 0);
}
+// Check whether measured time is the expected time (in milliseconds).
+// The upper tolerance is 1/2 sec so that the test doesn't fail even on
+// very slow or very loaded systems.
+#define time_assert(actual,expected) \
+ assert (actual > ((expected) - 50) && actual < ((expected) + 500));
+
#endif
diff --git a/tests/timeo.cpp b/tests/timeo.cpp
index 92c578b..2281556 100644
--- a/tests/timeo.cpp
+++ b/tests/timeo.cpp
@@ -66,9 +66,7 @@ int XS_TEST_MAIN ()
assert (rc == -1);
assert (xs_errno () == EAGAIN);
unsigned long elapsed = xs_stopwatch_stop (watch) / 1000;
-#if !defined _WIN32 || !defined _DEBUG
- assert (elapsed > 440 && elapsed < 550);
-#endif
+ time_assert (elapsed, timeout);
// Check whether connection during the wait doesn't distort the timeout.
timeout = 2000;
@@ -81,9 +79,7 @@ int XS_TEST_MAIN ()
assert (rc == -1);
assert (xs_errno () == EAGAIN);
elapsed = xs_stopwatch_stop (watch) / 1000;
-#if !defined _WIN32 || !defined _DEBUG
- assert (elapsed > 1900 && elapsed < 2100);
-#endif
+ time_assert (elapsed, timeout);
thread_join (thread);
// Check that timeouts don't break normal message transfer.