From e184bba0bca31d5ddde2d68deac74a21a3941762 Mon Sep 17 00:00:00 2001 From: edwinwu Date: Fri, 10 Jun 2022 11:51:19 -0700 Subject: [PATCH] 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 --- .../implementation/ios/Tests/GNCBLEATest.mm | 22 ------------------- .../implementation/ios/Tests/GNCBleTest.mm | 7 +++++- .../ios/Tests/GNCMultiThreadExecutorTest.mm | 8 +++---- 3 files changed, 10 insertions(+), 27 deletions(-) delete mode 100644 internal/platform/implementation/ios/Tests/GNCBLEATest.mm diff --git a/internal/platform/implementation/ios/Tests/GNCBLEATest.mm b/internal/platform/implementation/ios/Tests/GNCBLEATest.mm deleted file mode 100644 index 3818d9f6..00000000 --- a/internal/platform/implementation/ios/Tests/GNCBLEATest.mm +++ /dev/null @@ -1,22 +0,0 @@ -#import "internal/platform/implementation/ios/Tests/GNCBLEA.h" - -#import - -@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 diff --git a/internal/platform/implementation/ios/Tests/GNCBleTest.mm b/internal/platform/implementation/ios/Tests/GNCBleTest.mm index 27842e05..67c0c851 100644 --- a/internal/platform/implementation/ios/Tests/GNCBleTest.mm +++ b/internal/platform/implementation/ios/Tests/GNCBleTest.mm @@ -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()); } diff --git a/internal/platform/implementation/ios/Tests/GNCMultiThreadExecutorTest.mm b/internal/platform/implementation/ios/Tests/GNCMultiThreadExecutorTest.mm index 32bd2e32..f27dd5c5 100644 --- a/internal/platform/implementation/ios/Tests/GNCMultiThreadExecutorTest.mm +++ b/internal/platform/implementation/ios/Tests/GNCMultiThreadExecutorTest.mm @@ -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.