Skip to content

Commit

Permalink
Fix random failure in Darwin commissionable browse test. (#29943)
Browse files Browse the repository at this point in the history
The test sometimes did two browses, which could lead to it seeing more than 2
browse results, which would cause it to fail.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Nov 18, 2023
1 parent 207391f commit 592d4f0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/darwin/Framework/CHIPTests/MTRCommissionableBrowserTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
static MTRDeviceController * sController = nil;

@interface DeviceScannerDelegate : NSObject <MTRCommissionableBrowserDelegate>
@property (nonatomic) XCTestExpectation * expectation;
@property (nonatomic, nullable) XCTestExpectation * expectation;
@property (nonatomic) NSNumber * resultsCount;

- (instancetype)initWithExpectation:(XCTestExpectation *)expectation;
Expand All @@ -56,8 +56,26 @@ - (instancetype)initWithExpectation:(XCTestExpectation *)expectation
return self;
}

- (instancetype)init
{
if (!(self = [super init])) {
return nil;
}

_resultsCount = 0;
_expectation = nil;
return self;
}

- (void)controller:(MTRDeviceController *)controller didFindCommissionableDevice:(MTRCommissionableBrowserResult *)device
{
if (self.expectation == nil) {
// We are not actually supposed to be looking at results; don't do it,
// because we may be starting/stopping browse multiple times and seeing
// odd numbers of results.
return;
}

_resultsCount = @(_resultsCount.unsignedLongValue + 1);
if ([_resultsCount isEqual:@(kExpectedDiscoveredDevicesCount)]) {
[self.expectation fulfill];
Expand Down

0 comments on commit 592d4f0

Please sign in to comment.