From 79c73bfa042968bcb47cd5c7d6c86f0615b390c8 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 13 Dec 2024 13:58:32 -0500 Subject: [PATCH] Improve Darwin discovery test. (#36833) 1) Don't fulfill the expectation we are waiting on until after we have logged our "Found device" bit. 2) Have "Found device" and "Removed device" bits actually log the data that we are adding/removing to our result list, so that if they don't match it's easier to tell what's going on. --- .../CHIPTests/MTRCommissionableBrowserTests.m | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/src/darwin/Framework/CHIPTests/MTRCommissionableBrowserTests.m b/src/darwin/Framework/CHIPTests/MTRCommissionableBrowserTests.m index 0acfbd9a580371..d2b5f797e4514b 100644 --- a/src/darwin/Framework/CHIPTests/MTRCommissionableBrowserTests.m +++ b/src/darwin/Framework/CHIPTests/MTRCommissionableBrowserTests.m @@ -104,6 +104,22 @@ - (void)controller:(MTRDeviceController *)controller didFindCommissionableDevice [_results addObject:snapshot]; + XCTAssertLessThanOrEqual(_results.count, kExpectedDiscoveredDevicesCount); + + __auto_type instanceName = device.instanceName; + __auto_type vendorId = device.vendorID; + __auto_type productId = device.productID; + __auto_type discriminator = device.discriminator; + __auto_type commissioningMode = device.commissioningMode; + + XCTAssertEqual(instanceName.length, 16); // The instance name is random, so just ensure the len is right. + XCTAssertEqualObjects(vendorId, @(kTestVendorId)); + XCTAssertTrue([kTestProductIds containsObject:productId]); + XCTAssertTrue([kTestDiscriminators containsObject:discriminator]); + XCTAssertEqual(commissioningMode, YES); + + NSLog(@"Found device %@", snapshot); + if (_results.count == kExpectedDiscoveredDevicesCount) { // Do some sanity checking on our results and removedResults to make // sure we really only saw the relevant set of things. @@ -123,39 +139,17 @@ - (void)controller:(MTRDeviceController *)controller didFindCommissionableDevice [self.expectation fulfill]; } } - - XCTAssertLessThanOrEqual(_results.count, kExpectedDiscoveredDevicesCount); - - __auto_type instanceName = device.instanceName; - __auto_type vendorId = device.vendorID; - __auto_type productId = device.productID; - __auto_type discriminator = device.discriminator; - __auto_type commissioningMode = device.commissioningMode; - - XCTAssertEqual(instanceName.length, 16); // The instance name is random, so just ensure the len is right. - XCTAssertEqualObjects(vendorId, @(kTestVendorId)); - XCTAssertTrue([kTestProductIds containsObject:productId]); - XCTAssertTrue([kTestDiscriminators containsObject:discriminator]); - XCTAssertEqual(commissioningMode, YES); - - NSLog(@"Found Device (%@) with discriminator: %@ (vendor: %@, product: %@)", instanceName, discriminator, vendorId, productId); } - (void)controller:(MTRDeviceController *)controller didRemoveCommissionableDevice:(MTRCommissionableBrowserResult *)device { - __auto_type instanceName = device.instanceName; - __auto_type vendorId = device.vendorID; - __auto_type productId = device.productID; - __auto_type discriminator = device.discriminator; - - NSLog( - @"Removed Device (%@) with discriminator: %@ (vendor: %@, product: %@)", instanceName, discriminator, vendorId, productId); - __auto_type * snapshot = ResultSnapshot(device); - XCTAssertTrue([_results containsObject:snapshot], @"Removed device %@ is not something we found before", snapshot); + XCTAssertTrue([_results containsObject:snapshot], @"Removed device %@ is not something we found before: %@", snapshot, _results); [_removedResults addObject:snapshot]; [_results removeObject:snapshot]; + + NSLog(@"Removed device %@", snapshot); } @end