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
@@ -1,22 +0,0 @@
#import "internal/platform/implementation/ios/Tests/GNCBLEA.h"
#import <XCTest/XCTest.h>
@interface GNCBLEATest : XCTestCase
@end
@implementation GNCBLEATest
- (void)setUp {
[super setUp];
// Remove if not used.
}
- (void)tearDown {
// Remove if not used.
[super tearDown];
}
- (void)testFoo {
XCTAssertTrue(YES, @"A true test");
}
@end
@@ -57,7 +57,10 @@ static const TxPowerLevel kTxPowerLevel = TxPowerLevel::kHigh;
advertising_data.service_data = {{service_uuid, advertisement_bytes}};
XCTAssertTrue(_ble->StartAdvertising(advertising_data,
{.tx_power_level = kTxPowerLevel, .is_connectable = true}));
{.tx_power_level = kTxPowerLevel, .is_connectable = true}));
[NSThread sleepForTimeInterval:0.1];
XCTAssertTrue(_ble->StopAdvertising());
}
@@ -66,6 +69,8 @@ static const TxPowerLevel kTxPowerLevel = TxPowerLevel::kHigh;
XCTAssertTrue(_ble->StartScanning(service_uuid, kTxPowerLevel, {}));
[NSThread sleepForTimeInterval:0.1];
XCTAssertTrue(_ble->StopScanning());
}
@@ -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.