mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
Signed-off-by: Alexey Polyudov <apolyudov@google.com> Change-Id: I9850950db8bd84f0904ea1a413151887f52098cf
49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
#include "platform/public/count_down_latch.h"
|
|
|
|
#include "platform/public/single_thread_executor.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace location {
|
|
namespace nearby {
|
|
namespace {
|
|
|
|
TEST(CountDownLatch, ConstructorDestructorWorks) { CountDownLatch latch(1); }
|
|
|
|
TEST(CountDownLatch, LatchAwaitCanWait) {
|
|
CountDownLatch latch(1);
|
|
SingleThreadExecutor executor;
|
|
std::atomic_bool done = false;
|
|
executor.Execute([&done, &latch]() {
|
|
done = true;
|
|
latch.CountDown();
|
|
});
|
|
latch.Await();
|
|
EXPECT_TRUE(done);
|
|
}
|
|
|
|
TEST(CountDownLatch, LatchExtraCountDownIgnored) {
|
|
CountDownLatch latch(1);
|
|
SingleThreadExecutor executor;
|
|
std::atomic_bool done = false;
|
|
executor.Execute([&done, &latch]() {
|
|
done = true;
|
|
latch.CountDown();
|
|
latch.CountDown();
|
|
latch.CountDown();
|
|
});
|
|
latch.Await();
|
|
EXPECT_TRUE(done);
|
|
}
|
|
|
|
TEST(CountDownLatch, LatchAwaitWithTimeoutCanExpire) {
|
|
CountDownLatch latch(1);
|
|
SingleThreadExecutor executor;
|
|
auto response = latch.Await(absl::Milliseconds(100));
|
|
EXPECT_TRUE(response.ok());
|
|
EXPECT_FALSE(response.result());
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace nearby
|
|
} // namespace location
|