Skip to content

Commit

Permalink
Use ChipDnssdStopBrowse before exit
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Apr 25, 2023
1 parent 97ac5d9 commit 1385a7e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/platform/tests/TestDnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ struct DnssdContext

std::atomic<bool> mTimeoutExpired{ false };

intptr_t mBrowseIdentifier = 0;

unsigned int mBrowsedServicesCount = 0;
unsigned int mResolvedServicesCount = 0;
bool mEndOfInput = false;
Expand Down Expand Up @@ -85,7 +87,9 @@ static void HandleBrowse(void * context, DnssdService * services, size_t service

// Make sure that we will not be called again after end-of-input is set
NL_TEST_ASSERT(suite, ctx->mEndOfInput == false);
NL_TEST_ASSERT(suite, error == CHIP_NO_ERROR);
// Cancelled error is expected when the browse is stopped with
// ChipDnssdStopBrowse(), so we will not assert on it.
NL_TEST_ASSERT(suite, error == CHIP_NO_ERROR || error == CHIP_ERROR_CANCELLED);

ctx->mBrowsedServicesCount += servicesSize;
ctx->mEndOfInput = finalBrowse;
Expand Down Expand Up @@ -145,10 +149,10 @@ static void TestDnssdPubSub_DnssdInitCallback(void * context, CHIP_ERROR error)

NL_TEST_ASSERT(suite, ChipDnssdPublishService(&service, HandlePublish, context) == CHIP_NO_ERROR);

intptr_t browseIdentifier;
NL_TEST_ASSERT(suite,
ChipDnssdBrowse("_mock", DnssdServiceProtocol::kDnssdProtocolTcp, chip::Inet::IPAddressType::kAny,
chip::Inet::InterfaceId::Null(), HandleBrowse, context, &browseIdentifier) == CHIP_NO_ERROR);
chip::Inet::InterfaceId::Null(), HandleBrowse, context,
&ctx->mBrowseIdentifier) == CHIP_NO_ERROR);
}

void TestDnssdPubSub(nlTestSuite * inSuite, void * inContext)
Expand All @@ -168,6 +172,9 @@ void TestDnssdPubSub(nlTestSuite * inSuite, void * inContext)

NL_TEST_ASSERT(inSuite, !context.mTimeoutExpired);

// Stop browsing so we can safely shutdown DNS-SD
chip::Dnssd::ChipDnssdStopBrowse(context.mBrowseIdentifier);

chip::Dnssd::ChipDnssdShutdown();
}

Expand Down

0 comments on commit 1385a7e

Please sign in to comment.