diff options
Diffstat (limited to 'staging_vespalib/src/tests/metrics/mock_tick.h')
-rw-r--r-- | staging_vespalib/src/tests/metrics/mock_tick.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/staging_vespalib/src/tests/metrics/mock_tick.h b/staging_vespalib/src/tests/metrics/mock_tick.h new file mode 100644 index 00000000000..2f69f69fc91 --- /dev/null +++ b/staging_vespalib/src/tests/metrics/mock_tick.h @@ -0,0 +1,38 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include <atomic> +#include <condition_variable> +#include <mutex> +#include <vespa/vespalib/metrics/clock.h> + +namespace vespalib::metrics { + +// share the MockTick between the tested and the tester. +class MockTick : public Tick { +private: + std::mutex _lock; + std::atomic<bool> _runFlag; + std::atomic<bool> _provided; + std::atomic<bool> _blocked; + std::condition_variable _providedCond; + std::condition_variable _blockedCond; + TimeStamp _nextValue; + TimeStamp _prevValue; +public: + MockTick(); + TimeStamp next(TimeStamp prev) override; + void kill() override; + + void provide(TimeStamp value); + TimeStamp waitUntilBlocked(); +}; + +struct TickProxy : Tick { + std::shared_ptr<Tick> tick; + TickProxy(std::shared_ptr<Tick> tick_in) : tick(std::move(tick_in)) {} + TimeStamp next(TimeStamp prev) override { return tick->next(prev); } + void kill() override { tick->kill(); } +}; + +} // namespace vespalib::metrics |