mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Make sure timer is destroyed on the same thread callback is scheduled on.
PiperOrigin-RevId: 912325093
This commit is contained in:
committed by
Copybara-Service
parent
313efed9c9
commit
fc0fb02fee
@@ -38,8 +38,7 @@ FakeContext::FakeContext()
|
||||
fake_connectivity_manager_(std::make_unique<FakeConnectivityManager>()),
|
||||
fake_bluetooth_adapter_(std::make_unique<FakeBluetoothAdapter>()),
|
||||
fake_fast_initiation_manager_(
|
||||
std::make_unique<FakeFastInitiationManager>()),
|
||||
executor_(std::make_unique<FakeTaskRunner>(fake_clock_.get(), 5)) {}
|
||||
std::make_unique<FakeFastInitiationManager>()) {}
|
||||
|
||||
Clock* FakeContext::GetClock() const { return fake_clock_.get(); }
|
||||
|
||||
@@ -70,6 +69,4 @@ std::unique_ptr<TaskRunner> FakeContext::CreateConcurrentTaskRunner(
|
||||
return std::make_unique<FakeTaskRunner>(fake_clock_.get(), concurrent_count);
|
||||
}
|
||||
|
||||
TaskRunner* FakeContext::GetTaskRunner() { return executor_.get(); }
|
||||
|
||||
} // namespace nearby
|
||||
|
||||
@@ -47,7 +47,6 @@ class FakeContext : public Context {
|
||||
std::unique_ptr<TaskRunner> CreateSequencedTaskRunner() const override;
|
||||
std::unique_ptr<TaskRunner> CreateConcurrentTaskRunner(
|
||||
uint32_t concurrent_count) const override;
|
||||
TaskRunner* GetTaskRunner() override;
|
||||
|
||||
FakeClock* fake_clock() const { return fake_clock_.get(); }
|
||||
FakeConnectivityManager* fake_connectivity_manager() const {
|
||||
@@ -59,9 +58,6 @@ class FakeContext : public Context {
|
||||
FakeFastInitiationManager* fake_fast_initiation_manager() const {
|
||||
return fake_fast_initiation_manager_.get();
|
||||
}
|
||||
FakeTaskRunner* fake_task_runner() const {
|
||||
return executor_.get();
|
||||
}
|
||||
|
||||
FakeTaskRunner* last_sequenced_task_runner() const {
|
||||
return last_sequenced_task_runner_;
|
||||
@@ -72,7 +68,6 @@ class FakeContext : public Context {
|
||||
std::unique_ptr<FakeConnectivityManager> fake_connectivity_manager_;
|
||||
std::unique_ptr<FakeBluetoothAdapter> fake_bluetooth_adapter_;
|
||||
std::unique_ptr<FakeFastInitiationManager> fake_fast_initiation_manager_;
|
||||
std::unique_ptr<FakeTaskRunner> executor_;
|
||||
mutable FakeTaskRunner* last_sequenced_task_runner_ = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
#include "sharing/internal/test/fake_context.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/synchronization/notification.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/platform/task_runner.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace {
|
||||
@@ -31,18 +28,5 @@ TEST(FakeContext, TestAccessMockContext) {
|
||||
EXPECT_NE(context.CreateConcurrentTaskRunner(5), nullptr);
|
||||
}
|
||||
|
||||
TEST(FakeContext, ExecuteTask) {
|
||||
FakeContext context;
|
||||
absl::Notification notification;
|
||||
bool is_called = false;
|
||||
context.GetTaskRunner()->PostTask([&]() {
|
||||
is_called = true;
|
||||
notification.Notify();
|
||||
});
|
||||
|
||||
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(absl::Seconds(1)));
|
||||
EXPECT_TRUE(is_called);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace nearby
|
||||
|
||||
Reference in New Issue
Block a user