BEGIN_PUBLIC

Fixes A go/mobile_tsan error (data_race) found while running //third_party/nearby/internal/platform/implementation/ios/Tests:PlatformTests
END_PUBLIC

PiperOrigin-RevId: 454211152
This commit is contained in:
edwinwu
2022-06-10 11:52:58 -07:00
committed by Copybara-Service
parent 88ee3ba338
commit e184bba0bc
3 changed files with 10 additions and 27 deletions
@@ -51,11 +51,11 @@ using MultiThreadExecutor = location::nearby::api::SubmittableExecutor;
Runnable incrementer = [self]() { self.counter++; };
for (int i = 0; i < kIncrements; i++) {
executor->Execute(std::move(incrementer));
[NSThread sleepForTimeInterval:0.01];
}
// Check that the counter has the expected value after giving the runnables time to run.
[NSThread sleepForTimeInterval:0.01];
XCTAssertLessThan(abs(self.counter - kIncrements), 3);
XCTAssertLessThanOrEqual(abs(self.counter - kIncrements), 0);
}
// Tests that the executor submits runnables as expected.
@@ -67,11 +67,11 @@ using MultiThreadExecutor = location::nearby::api::SubmittableExecutor;
Runnable incrementer = [self]() { self.counter++; };
for (int i = 0; i < kIncrements; i++) {
executor->DoSubmit(std::move(incrementer));
[NSThread sleepForTimeInterval:0.01];
}
// Check that the counter has the expected value after giving the runnables time to run.
[NSThread sleepForTimeInterval:0.01];
XCTAssertLessThan(abs(self.counter - kIncrements), 3);
XCTAssertLessThanOrEqual(abs(self.counter - kIncrements), 0);
}
// Tests that fails to submit when the executor is shut down.