Skip to content

Commit

Permalink
Add Exit test
Browse files Browse the repository at this point in the history
  • Loading branch information
rnburn authored and Johannes Tax committed Jul 7, 2020
1 parent 2d2ea8e commit dc35d6e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions sdk/test/event/libevent/dispatcher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@
#include <chrono>

#include <gtest/gtest.h>
using opentelemetry::sdk::event::Timer;
using opentelemetry::sdk::event::libevent::Dispatcher;

TEST(DispatcherTest, Timer) {
TEST(DispatcherTest, Timer)
{
Dispatcher dispatcher;
std::chrono::steady_clock::time_point t1, t2;
auto timer = dispatcher.CreateTimer([&] {
t2 = std::chrono::steady_clock::now();
});
auto timer = dispatcher.CreateTimer([&] { t2 = std::chrono::steady_clock::now(); });
timer->EnableTimer(std::chrono::milliseconds{10});
t1 = std::chrono::steady_clock::now();
dispatcher.Run();
auto duration = t2 - t1;
EXPECT_TRUE(duration >= std::chrono::milliseconds{10});
EXPECT_TRUE(duration < std::chrono::milliseconds{20});
}

TEST(DispatcherTest, Exit)
{
Dispatcher dispatcher;
std::unique_ptr<Timer> timer;
auto f = [&] {
timer->EnableTimer(std::chrono::milliseconds{1});
dispatcher.Exit();
};
timer = dispatcher.CreateTimer(f);
dispatcher.Run();
}

0 comments on commit dc35d6e

Please sign in to comment.