diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-01-31 15:14:57 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-01-31 17:36:43 +0000 |
commit | 2503a877f21838e66e873f839a5b6fd0c38abfab (patch) | |
tree | 966ae9d7757aa58e7bff4aaa4b9b45b5f6668329 /vespalib/src | |
parent | 5ac0d0b71749c7555167c3c3906ff6843bf178f0 (diff) |
Use vespalib::duration for timeouts
Diffstat (limited to 'vespalib/src')
27 files changed, 63 insertions, 59 deletions
diff --git a/vespalib/src/tests/barrier/barrier_test.cpp b/vespalib/src/tests/barrier/barrier_test.cpp index f829b7fa5d8..2340476d4e0 100644 --- a/vespalib/src/tests/barrier/barrier_test.cpp +++ b/vespalib/src/tests/barrier/barrier_test.cpp @@ -13,9 +13,9 @@ struct Fixture { TEST_MT_F("require that barriers are satisfied by the appropriate number of threads", 3, Fixture(num_threads)) { if (thread_id == 0) { f1.latch.countDown(); - EXPECT_FALSE(f.latch.await(250)); + EXPECT_FALSE(f.latch.await(250ms)); EXPECT_TRUE(f.barrier.await()); - EXPECT_TRUE(f.latch.await(25000)); + EXPECT_TRUE(f.latch.await(25s)); } else { EXPECT_TRUE(f1.barrier.await()); f1.latch.countDown(); @@ -27,9 +27,9 @@ TEST_MT_F("require that barriers can be used multiple times", 3, Fixture(num_thr EXPECT_TRUE(f1.barrier.await()); if (thread_id == 0) { f1.latch.countDown(); - EXPECT_FALSE(f.latch.await(250)); + EXPECT_FALSE(f.latch.await(250ms)); EXPECT_TRUE(f.barrier.await()); - EXPECT_TRUE(f.latch.await(25000)); + EXPECT_TRUE(f.latch.await(25s)); } else { EXPECT_TRUE(f1.barrier.await()); f1.latch.countDown(); @@ -40,9 +40,9 @@ TEST_MT_F("require that barriers can be broken", 3, Fixture(num_threads)) { EXPECT_TRUE(f1.barrier.await()); if (thread_id == 0) { f1.latch.countDown(); - EXPECT_FALSE(f.latch.await(250)); + EXPECT_FALSE(f.latch.await(250ms)); f1.barrier.destroy(); - EXPECT_TRUE(f.latch.await(25000)); + EXPECT_TRUE(f.latch.await(25s)); } else { EXPECT_FALSE(f1.barrier.await()); f1.latch.countDown(); diff --git a/vespalib/src/tests/benchmark_timer/benchmark_timer_test.cpp b/vespalib/src/tests/benchmark_timer/benchmark_timer_test.cpp index 3f7187458d8..a1781abca81 100644 --- a/vespalib/src/tests/benchmark_timer/benchmark_timer_test.cpp +++ b/vespalib/src/tests/benchmark_timer/benchmark_timer_test.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/benchmark_timer.h> +#include <thread> using namespace vespalib; diff --git a/vespalib/src/tests/executor/blockingthreadstackexecutor_test.cpp b/vespalib/src/tests/executor/blockingthreadstackexecutor_test.cpp index 46db619516a..a0ef200ab83 100644 --- a/vespalib/src/tests/executor/blockingthreadstackexecutor_test.cpp +++ b/vespalib/src/tests/executor/blockingthreadstackexecutor_test.cpp @@ -1,6 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> - +#include <vespa/vespalib/testkit/time_bomb.h> #include <vespa/vespalib/util/blockingthreadstackexecutor.h> #include <vespa/vespalib/util/executor.h> #include <vespa/vespalib/util/backtrace.h> @@ -8,7 +8,7 @@ using namespace vespalib; -constexpr int msWait = 30000; +constexpr vespalib::duration waitTime = 30s; class MyTask : public Executor::Task { @@ -21,8 +21,8 @@ public: : _entryGate(entryGate), _exitLatch(exitLatch) {} - virtual void run() override { - _entryGate.await(msWait); + void run() override { + _entryGate.await(waitTime); _exitLatch.countDown(); } static Task::UP create(Gate &entryGate, CountDownLatch &exitLatch) { @@ -64,14 +64,14 @@ struct Fixture workersEntryGate.countDown(); } void waitForWorkers() { - workersExitLatch.await(msWait); + workersExitLatch.await(waitTime); } void assertExecuteIsBlocked() { - blockedExecuteGate.await(10); + blockedExecuteGate.await(10ms); EXPECT_EQUAL(1u, blockedExecuteGate.getCount()); } void waitForExecuteIsFinished() { - blockedExecuteGate.await(msWait); + blockedExecuteGate.await(waitTime); EXPECT_EQUAL(0u, blockedExecuteGate.getCount()); } ThreadUP blockedExecuteThread() { diff --git a/vespalib/src/tests/executor/stress_test.cpp b/vespalib/src/tests/executor/stress_test.cpp index 615e7addfd5..01873fa0480 100644 --- a/vespalib/src/tests/executor/stress_test.cpp +++ b/vespalib/src/tests/executor/stress_test.cpp @@ -4,6 +4,7 @@ #include <vespa/vespalib/util/executor.h> #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/vespalib/locale/c.h> +#include <thread> using namespace vespalib; using namespace std::literals; diff --git a/vespalib/src/tests/executor/threadstackexecutor_test.cpp b/vespalib/src/tests/executor/threadstackexecutor_test.cpp index b43a75f8244..e860a25c83c 100644 --- a/vespalib/src/tests/executor/threadstackexecutor_test.cpp +++ b/vespalib/src/tests/executor/threadstackexecutor_test.cpp @@ -147,9 +147,9 @@ TEST_MT_F("require that threads can wait for a specific task count", 7, WaitStat if (next_done < f1.block_task.size()) { f1.block_task[f1.block_task.size() - 1 - next_done].countDown(); } - EXPECT_TRUE(f1.wait_done[next_done].await(25000)); + EXPECT_TRUE(f1.wait_done[next_done].await(25s)); for (size_t i = 0; i < next_done; ++i) { - EXPECT_TRUE(!f1.wait_done[i].await(20)); + EXPECT_TRUE(!f1.wait_done[i].await(20ms)); } } } else { diff --git a/vespalib/src/tests/latch/latch_test.cpp b/vespalib/src/tests/latch/latch_test.cpp index f29b673e508..a0daf7ef7d5 100644 --- a/vespalib/src/tests/latch/latch_test.cpp +++ b/vespalib/src/tests/latch/latch_test.cpp @@ -1,6 +1,7 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/time_bomb.h> #include <vespa/vespalib/util/gate.h> #include <vespa/vespalib/util/latch.h> @@ -17,9 +18,9 @@ TEST("require that write then read works") { TEST_MT_FFF("require that read waits for write", 2, Latch<int>(), Gate(), TimeBomb(60)) { if (thread_id == 0) { - EXPECT_TRUE(!f2.await(10)); + EXPECT_TRUE(!f2.await(10ms)); f1.write(123); - EXPECT_TRUE(f2.await(60000)); + EXPECT_TRUE(f2.await(60s)); } else { EXPECT_EQUAL(f1.read(), 123); f2.countDown(); @@ -32,9 +33,9 @@ TEST_MT_FFF("require that write waits for read", 2, Latch<int>(), Gate(), TimeBo f1.write(456); f2.countDown(); } else { - EXPECT_TRUE(!f2.await(10)); + EXPECT_TRUE(!f2.await(10ms)); EXPECT_EQUAL(f1.read(), 123); - EXPECT_TRUE(f2.await(60000)); + EXPECT_TRUE(f2.await(60s)); EXPECT_EQUAL(f1.read(), 456); } } diff --git a/vespalib/src/tests/net/async_resolver/async_resolver_test.cpp b/vespalib/src/tests/net/async_resolver/async_resolver_test.cpp index f04fe549c09..8f3cad135ec 100644 --- a/vespalib/src/tests/net/async_resolver/async_resolver_test.cpp +++ b/vespalib/src/tests/net/async_resolver/async_resolver_test.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/time_bomb.h> #include <vespa/vespalib/net/async_resolver.h> #include <vespa/vespalib/net/socket_spec.h> #include <atomic> diff --git a/vespalib/src/tests/net/crypto_socket/crypto_socket_test.cpp b/vespalib/src/tests/net/crypto_socket/crypto_socket_test.cpp index e938e15f4e6..7230f97818f 100644 --- a/vespalib/src/tests/net/crypto_socket/crypto_socket_test.cpp +++ b/vespalib/src/tests/net/crypto_socket/crypto_socket_test.cpp @@ -1,6 +1,7 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/time_bomb.h> #include <vespa/vespalib/net/crypto_engine.h> #include <vespa/vespalib/net/tls/tls_crypto_engine.h> #include <vespa/vespalib/net/tls/maybe_tls_crypto_engine.h> diff --git a/vespalib/src/tests/net/selector/selector_test.cpp b/vespalib/src/tests/net/selector/selector_test.cpp index 5c91dfdc122..d13821ce2d0 100644 --- a/vespalib/src/tests/net/selector/selector_test.cpp +++ b/vespalib/src/tests/net/selector/selector_test.cpp @@ -1,5 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/time_bomb.h> #include <vespa/vespalib/net/socket_address.h> #include <vespa/vespalib/net/selector.h> #include <vespa/vespalib/net/socket_utils.h> diff --git a/vespalib/src/tests/net/send_fd/send_fd_test.cpp b/vespalib/src/tests/net/send_fd/send_fd_test.cpp index e9921f75207..cc367996bd6 100644 --- a/vespalib/src/tests/net/send_fd/send_fd_test.cpp +++ b/vespalib/src/tests/net/send_fd/send_fd_test.cpp @@ -1,5 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/time_bomb.h> + #include <vespa/vespalib/net/selector.h> #include <vespa/vespalib/net/socket_spec.h> #include <vespa/vespalib/net/server_socket.h> diff --git a/vespalib/src/tests/net/socket/socket_test.cpp b/vespalib/src/tests/net/socket/socket_test.cpp index 08893c9273b..e3b13b69884 100644 --- a/vespalib/src/tests/net/socket/socket_test.cpp +++ b/vespalib/src/tests/net/socket/socket_test.cpp @@ -1,5 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/time_bomb.h> #include <vespa/vespalib/net/selector.h> #include <vespa/vespalib/net/socket_spec.h> #include <vespa/vespalib/net/server_socket.h> @@ -9,7 +10,6 @@ #include <vespa/vespalib/test/socket_options_verifier.h> #include <thread> #include <functional> -#include <chrono> #include <unistd.h> #include <sys/stat.h> diff --git a/vespalib/src/tests/net/sync_crypto_socket/sync_crypto_socket_test.cpp b/vespalib/src/tests/net/sync_crypto_socket/sync_crypto_socket_test.cpp index 56767051dad..8a4961b786b 100644 --- a/vespalib/src/tests/net/sync_crypto_socket/sync_crypto_socket_test.cpp +++ b/vespalib/src/tests/net/sync_crypto_socket/sync_crypto_socket_test.cpp @@ -1,6 +1,7 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/time_bomb.h> #include <vespa/vespalib/net/crypto_engine.h> #include <vespa/vespalib/net/tls/tls_crypto_engine.h> #include <vespa/vespalib/net/tls/maybe_tls_crypto_engine.h> diff --git a/vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp b/vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp index 5dc85bc567f..4631f19807e 100644 --- a/vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp +++ b/vespalib/src/tests/net/tls/auto_reloading_tls_crypto_engine/auto_reloading_tls_crypto_engine_test.cpp @@ -7,9 +7,7 @@ #include <vespa/vespalib/net/tls/transport_security_options_reading.h> #include <vespa/vespalib/net/tls/impl/openssl_tls_context_impl.h> #include <vespa/vespalib/testkit/test_kit.h> - -#include <chrono> - +#include <vespa/vespalib/testkit/time_bomb.h> #include <openssl/ssl.h> using namespace vespalib; diff --git a/vespalib/src/tests/portal/handle_manager/handle_manager_test.cpp b/vespalib/src/tests/portal/handle_manager/handle_manager_test.cpp index 4ce25aa0a7a..844622577e2 100644 --- a/vespalib/src/tests/portal/handle_manager/handle_manager_test.cpp +++ b/vespalib/src/tests/portal/handle_manager/handle_manager_test.cpp @@ -1,11 +1,8 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/time_bomb.h> #include <vespa/vespalib/portal/handle_manager.h> -#include <vespa/vespalib/util/gate.h> - -#include <thread> -#include <chrono> #include <atomic> using namespace vespalib; @@ -85,9 +82,9 @@ TEST_MT_FF("require that destroy waits for active handle guards", 2, Fixture(), { auto guard = f1.manager.lock(f1.handle); TEST_BARRIER(); // #1 - EXPECT_TRUE(!f1.gate.await(20)); + EXPECT_TRUE(!f1.gate.await(20ms)); } - EXPECT_TRUE(f1.gate.await(60000)); + EXPECT_TRUE(f1.gate.await(60s)); } else { TEST_BARRIER(); // #1 EXPECT_TRUE(f1.manager.destroy(f1.handle)); diff --git a/vespalib/src/tests/portal/portal_test.cpp b/vespalib/src/tests/portal/portal_test.cpp index 07d3b9e1bfb..d708f81bdde 100644 --- a/vespalib/src/tests/portal/portal_test.cpp +++ b/vespalib/src/tests/portal/portal_test.cpp @@ -1,6 +1,7 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/time_bomb.h> #include <vespa/vespalib/portal/portal.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/util/stringfmt.h> @@ -305,7 +306,7 @@ TEST_MT_FF("require that GET requests can be completed in another thread", 2, if (thread_id == 0) { Portal::GetRequest req = f1.latch.read(); f1.exit_callback.countDown(); - std::this_thread::sleep_for(std::chrono::milliseconds(5)); + std::this_thread::sleep_for(5ms); req.respond_with_content("text/plain", "hello"); } else { auto result = fetch(f1.portal->listen_port(), null_crypto(), "/test"); @@ -318,9 +319,9 @@ TEST_MT_FFF("require that bind token destruction waits for active callbacks", 3, { if (thread_id == 0) { Portal::GetRequest req = f1.latch.read(); - EXPECT_TRUE(!f2.await(20)); + EXPECT_TRUE(!f2.await(20ms)); f1.exit_callback.countDown(); - EXPECT_TRUE(f2.await(60000)); + EXPECT_TRUE(f2.await(60s)); req.respond_with_content("application/json", "[1,2,3]"); } else if (thread_id == 1) { f1.enter_callback.await(); @@ -338,9 +339,9 @@ TEST_MT_FFF("require that portal destruction waits for request completion", 3, if (thread_id == 0) { Portal::GetRequest req = f1.latch.read(); f1.exit_callback.countDown(); - EXPECT_TRUE(!f2.await(20)); + EXPECT_TRUE(!f2.await(20ms)); req.respond_with_content("application/json", "[1,2,3]"); - EXPECT_TRUE(f2.await(60000)); + EXPECT_TRUE(f2.await(60s)); } else if (thread_id == 1) { f1.enter_callback.await(); f1.bound.reset(); diff --git a/vespalib/src/tests/portal/reactor/reactor_test.cpp b/vespalib/src/tests/portal/reactor/reactor_test.cpp index b0abc2c9e46..b14bb1dbd3f 100644 --- a/vespalib/src/tests/portal/reactor/reactor_test.cpp +++ b/vespalib/src/tests/portal/reactor/reactor_test.cpp @@ -1,14 +1,11 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/time_bomb.h> #include <vespa/vespalib/net/socket_handle.h> #include <vespa/vespalib/net/socket_utils.h> #include <vespa/vespalib/portal/reactor.h> #include <vespa/vespalib/util/gate.h> - -#include <thread> -#include <chrono> - #include <sys/types.h> #include <sys/socket.h> #include <fcntl.h> @@ -150,9 +147,9 @@ TEST_MT_FFFF("require that reactor token destruction waits for io event handling if (thread_id == 0) { f2.enter_callback.await(); TEST_BARRIER(); // #1 - EXPECT_TRUE(!f3.await(20)); + EXPECT_TRUE(!f3.await(20ms)); f2.exit_callback.countDown(); - EXPECT_TRUE(f3.await(60000)); + EXPECT_TRUE(f3.await(60s)); } else { TEST_BARRIER(); // #1 f2.token.reset(); diff --git a/vespalib/src/tests/rendezvous/rendezvous_test.cpp b/vespalib/src/tests/rendezvous/rendezvous_test.cpp index f4ec7870ad5..6a3e87563ed 100644 --- a/vespalib/src/tests/rendezvous/rendezvous_test.cpp +++ b/vespalib/src/tests/rendezvous/rendezvous_test.cpp @@ -149,13 +149,13 @@ TEST_MT_FFFF("require that mingle is not called until all threads are present", for (bool ext_id: {false, true}) { CountDownLatch &latch = ext_id ? f4 : f2; if (thread_id == 0) { - EXPECT_FALSE(latch.await(20)); + EXPECT_FALSE(latch.await(20ms)); if (ext_id) { EXPECT_EQUAL(3u, f3.rendezvous(thread_id, thread_id).first); } else { EXPECT_EQUAL(3u, f1.rendezvous(thread_id).first); } - EXPECT_TRUE(latch.await(25000)); + EXPECT_TRUE(latch.await(25s)); } else { if (ext_id) { EXPECT_EQUAL(3u, f3.rendezvous(thread_id, thread_id).first); @@ -183,7 +183,7 @@ TEST_MT_FF("require that rendezvous can be run with additional threads", 100, Ad EXPECT_EQUAL(4950u, f1.rendezvous(res.first).first); f2.countDown(); } - EXPECT_TRUE(f2.await(25000)); + EXPECT_TRUE(f2.await(25s)); } TEST_MT_FF("require that mingle can modify its own copy of input values", 10, Modify<false>(num_threads), Modify<true>(num_threads)) { diff --git a/vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp b/vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp index d3c562c583c..178a6c49fca 100644 --- a/vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp +++ b/vespalib/src/tests/simple_thread_bundle/simple_thread_bundle_test.cpp @@ -3,6 +3,7 @@ #include <vespa/vespalib/util/simple_thread_bundle.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/util/box.h> +#include <thread> using namespace vespalib; using namespace vespalib::fixed_thread_bundle; @@ -112,9 +113,9 @@ TEST_MT_FFF("require that bundle run waits for all targets", 2, SimpleThreadBund f2.check(Box<size_t>().add(1).add(1).add(1)); f3.done.countDown(); } else { - EXPECT_FALSE(f3.done.await(20)); + EXPECT_FALSE(f3.done.await(20ms)); f3.start.countDown(); - EXPECT_TRUE(f3.done.await(10000)); + EXPECT_TRUE(f3.done.await(10s)); } } diff --git a/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp b/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp index 71bae66ed2f..f1021ba3b09 100644 --- a/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp +++ b/vespalib/src/tests/simple_thread_bundle/threading_speed_test.cpp @@ -2,6 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/simple_thread_bundle.h> #include <vespa/vespalib/util/box.h> +#include <thread> using namespace vespalib; diff --git a/vespalib/src/tests/sync/sync_test.cpp b/vespalib/src/tests/sync/sync_test.cpp index 417a9779f9d..e58135d8723 100644 --- a/vespalib/src/tests/sync/sync_test.cpp +++ b/vespalib/src/tests/sync/sync_test.cpp @@ -37,12 +37,12 @@ TEST("test gate dropping below zero") { TEST("test gate non blocking await return correct states") { Gate gate; EXPECT_EQUAL(gate.getCount(), 1u); - EXPECT_EQUAL(gate.await(0), false); - EXPECT_EQUAL(gate.await(10), false); + EXPECT_EQUAL(gate.await(0ms), false); + EXPECT_EQUAL(gate.await(10ms), false); gate.countDown(); EXPECT_EQUAL(gate.getCount(), 0u); - EXPECT_EQUAL(gate.await(0), true); - EXPECT_EQUAL(gate.await(10), true); + EXPECT_EQUAL(gate.await(0ms), true); + EXPECT_EQUAL(gate.await(10ms), true); } TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/vespalib/src/tests/testkit-time_bomb/testkit-time_bomb_test.cpp b/vespalib/src/tests/testkit-time_bomb/testkit-time_bomb_test.cpp index af595db5ae7..5496fedb703 100644 --- a/vespalib/src/tests/testkit-time_bomb/testkit-time_bomb_test.cpp +++ b/vespalib/src/tests/testkit-time_bomb/testkit-time_bomb_test.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/testkit/time_bomb.h> TEST_MT_F("use time bomb in multi-threaded test", 4, vespalib::TimeBomb(60)) { EXPECT_TRUE(true); diff --git a/vespalib/src/tests/thread/thread_test.cpp b/vespalib/src/tests/thread/thread_test.cpp index bcd38190c7e..5820f329b4f 100644 --- a/vespalib/src/tests/thread/thread_test.cpp +++ b/vespalib/src/tests/thread/thread_test.cpp @@ -2,6 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/thread.h> +#include <thread> using namespace vespalib; diff --git a/vespalib/src/tests/time/time_box_test.cpp b/vespalib/src/tests/time/time_box_test.cpp index 3c58b929487..32ac68e7254 100644 --- a/vespalib/src/tests/time/time_box_test.cpp +++ b/vespalib/src/tests/time/time_box_test.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/time/time_box.h> +#include <thread> TEST("require that long-lived timebox returns falling time left numbers") { vespalib::TimeBox box(3600); diff --git a/vespalib/src/tests/websocket/websocket_test.cpp b/vespalib/src/tests/websocket/websocket_test.cpp index db031b247b4..d9cd70c09d1 100644 --- a/vespalib/src/tests/websocket/websocket_test.cpp +++ b/vespalib/src/tests/websocket/websocket_test.cpp @@ -5,8 +5,7 @@ #include <vespa/vespalib/websocket/acceptor.h> #include <vespa/vespalib/websocket/key.h> #include <vespa/vespalib/websocket/buffer.h> -#include <thread> -#include <chrono> +#include <vespa/vespalib/util/gate.h> using namespace vespalib; using namespace vespalib::ws; @@ -103,7 +102,7 @@ TEST("require that an acceptor can accept connections asynchronously") { Receptor<Socket> server; Acceptor acceptor(0, server); Socket::UP client = SimpleSocket::connect(SocketSpec::from_port(acceptor.port())); - server.gate.await(60000); + server.gate.await(60s); ASSERT_TRUE(server.obj.get() != nullptr); ASSERT_TRUE(client.get() != nullptr); TEST_DO(verify_socket_io_async(*server.obj, *client)); diff --git a/vespalib/src/vespa/vespalib/testkit/test_kit.h b/vespalib/src/vespa/vespalib/testkit/test_kit.h index 17746c5b0fc..0587396ceda 100644 --- a/vespalib/src/vespa/vespalib/testkit/test_kit.h +++ b/vespalib/src/vespa/vespalib/testkit/test_kit.h @@ -9,5 +9,4 @@ #include "test_master.h" #include "test_hook.h" #include "test_state_guard.h" -#include "time_bomb.h" #include <vespa/vespalib/util/time.h> diff --git a/vespalib/src/vespa/vespalib/testkit/time_bomb.cpp b/vespalib/src/vespa/vespalib/testkit/time_bomb.cpp index cbefa285384..2d75fcdd18f 100644 --- a/vespalib/src/vespa/vespalib/testkit/time_bomb.cpp +++ b/vespalib/src/vespa/vespalib/testkit/time_bomb.cpp @@ -10,14 +10,14 @@ namespace { void bomb(Gate &gate, size_t seconds) { if (seconds > 5) { - if (gate.await((seconds - 5) * 1000)) { + if (gate.await(from_s(seconds - 5))) { return; } } size_t countdown = std::min(seconds, size_t(5)); while (countdown > 0) { fprintf(stderr, "...%zu...\n", countdown--); - if (gate.await(1000)) { + if (gate.await(1s)) { return; } } diff --git a/vespalib/src/vespa/vespalib/util/count_down_latch.h b/vespalib/src/vespa/vespalib/util/count_down_latch.h index 420be8f7ab2..54b36b414d6 100644 --- a/vespalib/src/vespa/vespalib/util/count_down_latch.h +++ b/vespalib/src/vespa/vespalib/util/count_down_latch.h @@ -2,9 +2,9 @@ #pragma once +#include "time.h" #include <mutex> #include <condition_variable> -#include <chrono> namespace vespalib { @@ -71,10 +71,9 @@ public: * @param maxwait the maximum number of milliseconds to wait * @return true if the counter reached 0, false if we timed out **/ - bool await(int maxwait) { - auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(maxwait); + bool await(vespalib::duration maxwait) { std::unique_lock<std::mutex> guard(_lock); - return _cond.wait_until(guard, deadline, [this]() { return (_count == 0); }); + return _cond.wait_for(guard, maxwait, [this]() { return (_count == 0); }); } /** |