Skip to content

Commit

Permalink
Test timeout in case of Avahi not running
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Apr 25, 2023
1 parent 8dafff9 commit 97ac5d9
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/platform/tests/TestDnssd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
*
*/

#include <condition_variable>
#include <mutex>
#include <thread>
#include <atomic>

#include <nlunit-test.h>

Expand All @@ -43,6 +41,8 @@ struct DnssdContext
{
nlTestSuite * mTestSuite;

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

unsigned int mBrowsedServicesCount = 0;
unsigned int mResolvedServicesCount = 0;
bool mEndOfInput = false;
Expand Down Expand Up @@ -102,6 +102,14 @@ static void HandleBrowse(void * context, DnssdService * services, size_t service
}
}

static void Timeout(chip::System::Layer * systemLayer, void * context)
{
auto * ctx = static_cast<DnssdContext *>(context);
ChipLogError(DeviceLayer, "mDNS test timeout, is avahi daemon running?");
ctx->mTimeoutExpired = true;
chip::DeviceLayer::PlatformMgr().StopEventLoopTask();
}

static void DnssdErrorCallback(void * context, CHIP_ERROR error)
{
auto * ctx = static_cast<DnssdContext *>(context);
Expand Down Expand Up @@ -150,11 +158,16 @@ void TestDnssdPubSub(nlTestSuite * inSuite, void * inContext)

NL_TEST_ASSERT(inSuite,
chip::Dnssd::ChipDnssdInit(TestDnssdPubSub_DnssdInitCallback, DnssdErrorCallback, &context) == CHIP_NO_ERROR);
NL_TEST_ASSERT(inSuite,
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(5), Timeout, &context) ==
CHIP_NO_ERROR);

ChipLogProgress(DeviceLayer, "Start EventLoop");
chip::DeviceLayer::PlatformMgr().RunEventLoop();
ChipLogProgress(DeviceLayer, "End EventLoop");

NL_TEST_ASSERT(inSuite, !context.mTimeoutExpired);

chip::Dnssd::ChipDnssdShutdown();
}

Expand Down

0 comments on commit 97ac5d9

Please sign in to comment.