Skip to content

Commit ee49af6

Browse files
ftsuicopybara-github
authored andcommitted
FakeTaskRunner::WaitForRunningTasksWithTimeout
PiperOrigin-RevId: 694283408
1 parent cb07eea commit ee49af6

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

sharing/internal/test/fake_context.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "internal/platform/task_runner.h"
2525
#include "internal/platform/timer.h"
2626
#include "internal/test/fake_clock.h"
27+
#include "internal/test/fake_task_runner.h"
2728
#include "sharing/internal/api/bluetooth_adapter.h"
2829
#include "sharing/internal/api/fast_initiation_manager.h"
2930
#include "sharing/internal/api/wifi_adapter.h"
@@ -65,14 +66,17 @@ class FakeContext : public Context {
6566
FakeFastInitiationManager* fake_fast_initiation_manager() const {
6667
return fake_fast_initiation_manager_.get();
6768
}
69+
FakeTaskRunner* fake_task_runner() const {
70+
return executor_.get();
71+
}
6872

6973
private:
7074
std::unique_ptr<FakeClock> fake_clock_;
7175
std::unique_ptr<FakeConnectivityManager> fake_connectivity_manager_;
7276
std::unique_ptr<FakeBluetoothAdapter> fake_bluetooth_adapter_;
7377
std::unique_ptr<FakeWifiAdapter> fake_wifi_adapter_;
7478
std::unique_ptr<FakeFastInitiationManager> fake_fast_initiation_manager_;
75-
std::unique_ptr<TaskRunner> executor_;
79+
std::unique_ptr<FakeTaskRunner> executor_;
7680
};
7781

7882
} // namespace nearby

sharing/local_device_data/nearby_share_local_device_data_manager_impl_test.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ class NearbyShareLocalDeviceDataManagerImplTest
124124
~NearbyShareLocalDeviceDataManagerImplTest() override = default;
125125

126126
void SetUp() override {
127-
FakeTaskRunner::ResetPendingTasksCount();
128127
prefs::RegisterNearbySharingPrefs(preference_manager_);
129128
NearbyShareSchedulerFactory::SetFactoryForTesting(&scheduler_factory_);
130129

@@ -235,8 +234,8 @@ class NearbyShareLocalDeviceDataManagerImplTest
235234
}
236235

237236
void Sync() {
238-
EXPECT_TRUE(FakeTaskRunner::WaitForRunningTasksWithTimeout(
239-
absl::Milliseconds(1000)));
237+
EXPECT_TRUE(
238+
context_.fake_task_runner()->SyncWithTimeout(absl::Milliseconds(1000)));
240239
}
241240

242241
private:

sharing/nearby_connection_impl_test.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ namespace sharing {
3232
namespace {
3333

3434
TEST(NearbyConnectionImpl, DestructorBeforeReaderDestructor) {
35-
FakeTaskRunner::ResetPendingTasksCount();
3635
FakeNearbyConnectionsManager connection_manager;
3736
FakeClock fake_clock;
3837
FakeTaskRunner fake_task_runner(&fake_clock, 1);
@@ -50,14 +49,13 @@ TEST(NearbyConnectionImpl, DestructorBeforeReaderDestructor) {
5049
called = true;
5150
notification.Notify();
5251
});
53-
EXPECT_TRUE(FakeTaskRunner::WaitForRunningTasksWithTimeout(absl::Seconds(1)));
52+
EXPECT_TRUE(fake_task_runner.SyncWithTimeout(absl::Seconds(1)));
5453
connection.reset();
5554
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(absl::Seconds(1)));
5655
EXPECT_TRUE(called);
5756
}
5857

5958
TEST(NearbyConnectionImpl, DestructorAfterReaderDestructor) {
60-
FakeTaskRunner::ResetPendingTasksCount();
6159
FakeNearbyConnectionsManager connection_manager;
6260
FakeClock fake_clock;
6361
FakeTaskRunner fake_task_runner(&fake_clock, 1);
@@ -76,7 +74,7 @@ TEST(NearbyConnectionImpl, DestructorAfterReaderDestructor) {
7674
notification.Notify();
7775
});
7876

79-
EXPECT_TRUE(FakeTaskRunner::WaitForRunningTasksWithTimeout(absl::Seconds(1)));
77+
EXPECT_TRUE(fake_task_runner.SyncWithTimeout(absl::Seconds(1)));
8078
frames_reader.reset();
8179
connection.reset();
8280
EXPECT_TRUE(notification.WaitForNotificationWithTimeout(absl::Seconds(1)));

sharing/nearby_sharing_settings_test.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ class NearbyShareSettingsTest : public ::testing::Test {
118118
public:
119119
NearbyShareSettingsTest()
120120
: local_device_data_manager_(kDefaultDeviceName) {
121-
FakeTaskRunner::ResetPendingTasksCount();
122121
prefs::RegisterNearbySharingPrefs(preference_manager_);
123122
nearby_share_settings_ = std::make_unique<NearbyShareSettings>(
124123
&context_, context_.GetClock(), fake_device_info_, preference_manager_,
@@ -146,7 +145,7 @@ class NearbyShareSettingsTest : public ::testing::Test {
146145
// Waits for running tasks to complete.
147146
void Flush() {
148147
absl::SleepFor(absl::Seconds(1));
149-
FakeTaskRunner::WaitForRunningTasksWithTimeout(absl::Milliseconds(200));
148+
context_.fake_task_runner()->SyncWithTimeout(absl::Milliseconds(200));
150149
}
151150

152151
void FastForward(absl::Duration duration) {

0 commit comments

Comments
 (0)