summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-05-15 10:53:04 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2023-05-15 10:53:04 +0000
commit6aa599ad8c189a3a78b7c7f3ac7962ac043c0108 (patch)
treea98615dbcd91566f6ec6368064c55018d1b8c15d /vespalib
parentd353b99f58fa5aef9da820f0a561748d2578a9f3 (diff)
Use a timeBomb to ensure test terminates on error.
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/testkit/time_bomb.cpp12
-rw-r--r--vespalib/src/vespa/vespalib/testkit/time_bomb.h3
2 files changed, 8 insertions, 7 deletions
diff --git a/vespalib/src/vespa/vespalib/testkit/time_bomb.cpp b/vespalib/src/vespa/vespalib/testkit/time_bomb.cpp
index 22cd535f434..9d4b2ea30c8 100644
--- a/vespalib/src/vespa/vespalib/testkit/time_bomb.cpp
+++ b/vespalib/src/vespa/vespalib/testkit/time_bomb.cpp
@@ -8,13 +8,13 @@ namespace vespalib {
namespace {
-void bomb(Gate &gate, size_t seconds) {
- if (seconds > 5) {
- if (gate.await(from_s(seconds - 5))) {
+void bomb(Gate &gate, vespalib::duration timeout) {
+ if (timeout > 5s) {
+ if (gate.await(timeout - 5s)) {
return;
}
}
- size_t countdown = std::min(seconds, size_t(5));
+ size_t countdown = std::min(count_s(timeout), 5l);
while (countdown > 0) {
fprintf(stderr, "...%zu...\n", countdown--);
if (gate.await(1s)) {
@@ -27,9 +27,9 @@ void bomb(Gate &gate, size_t seconds) {
} // namespace vespalib::<unnamed>
-TimeBomb::TimeBomb(size_t seconds)
+TimeBomb::TimeBomb(duration timeout)
: _gate(),
- _thread(bomb, std::ref(_gate), seconds)
+ _thread(bomb, std::ref(_gate), timeout)
{
}
diff --git a/vespalib/src/vespa/vespalib/testkit/time_bomb.h b/vespalib/src/vespa/vespalib/testkit/time_bomb.h
index a88aeeadd9a..ca02e7cda43 100644
--- a/vespalib/src/vespa/vespalib/testkit/time_bomb.h
+++ b/vespalib/src/vespa/vespalib/testkit/time_bomb.h
@@ -21,7 +21,8 @@ private:
Gate _gate;
std::thread _thread;
public:
- TimeBomb(size_t seconds);
+ TimeBomb(size_t seconds) : TimeBomb(from_s(seconds)) {}
+ TimeBomb(vespalib::duration duration);
~TimeBomb(); // defuse the bomb
};