Skip to content

Commit

Permalink
Break the dependency between tests that use MessagingContext (#33588)
Browse files Browse the repository at this point in the history
* Fix dependency between tests

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jun 18, 2024
1 parent 6f44fd8 commit 2369972
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/messaging/tests/MessagingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ CHIP_ERROR MessagingContext::Init(TransportMgrBase * transport, IOContext * ioCo
ReturnErrorOnFailure(mExchangeManager.Init(&mSessionManager));
ReturnErrorOnFailure(mMessageCounterManager.Init(&mExchangeManager));

if (sInitializeNodes)
if (mInitializeNodes)
{
ReturnErrorOnFailure(CreateAliceFabric());
ReturnErrorOnFailure(CreateBobFabric());
Expand Down Expand Up @@ -112,8 +112,6 @@ using namespace System::Clock::Literals;
constexpr chip::System::Clock::Timeout MessagingContext::kResponsiveIdleRetransTimeout;
constexpr chip::System::Clock::Timeout MessagingContext::kResponsiveActiveRetransTimeout;

bool MessagingContext::sInitializeNodes = true;

void MessagingContext::SetMRPMode(MRPMode mode)
{
if (mode == MRPMode::kDefault)
Expand Down
4 changes: 2 additions & 2 deletions src/messaging/tests/MessagingContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MessagingContext : public PlatformMemoryUser
~MessagingContext() { VerifyOrDie(mInitialized == false); }

// Whether Alice and Bob are initialized, must be called before Init
static void ConfigInitializeNodes(bool initializeNodes) { sInitializeNodes = initializeNodes; }
void ConfigInitializeNodes(bool initializeNodes) { mInitializeNodes = initializeNodes; }

/// Initialize the underlying layers and test suite pointer
CHIP_ERROR Init(TransportMgrBase * transport, IOContext * io);
Expand Down Expand Up @@ -178,7 +178,7 @@ class MessagingContext : public PlatformMemoryUser
System::Layer & GetSystemLayer() { return mIOContext->GetSystemLayer(); }

private:
static bool sInitializeNodes;
bool mInitializeNodes = true;
bool mInitialized;
FabricTable mFabricTable;

Expand Down
8 changes: 7 additions & 1 deletion src/protocols/secure_channel/tests/TestCASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ class TestContext : public Test::LoopbackMessagingContext
static void SetUpTestSuite();
// Performs shared teardown for all tests in the test suite
static void TearDownTestSuite();

virtual void SetUp() override
{
ConfigInitializeNodes(false);
chip::Test::LoopbackMessagingContext::SetUp();
}
virtual void TearDown() override { chip::Test::LoopbackMessagingContext::TearDown(); }
};

void ServiceEvents(TestContext & ctx)
Expand Down Expand Up @@ -329,7 +336,6 @@ CHIP_ERROR InitCredentialSets()

void TestContext::SetUpTestSuite()
{
ConfigInitializeNodes(false);
CHIP_ERROR err = CHIP_NO_ERROR;
LoopbackMessagingContext::SetUpTestSuite();
// TODO: use ASSERT_EQ, once transition to pw_unit_test is complete
Expand Down
9 changes: 7 additions & 2 deletions src/protocols/secure_channel/tests/TestPASESession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ class TestContext : public chip::Test::LoopbackMessagingContext
{
public:
// Performs shared setup for all tests in the test suite
static void SetUpTestSuite()
static void SetUpTestSuite() { chip::Test::LoopbackMessagingContext::SetUpTestSuite(); }
static void TearDownTestSuite() { chip::Test::LoopbackMessagingContext::TearDownTestSuite(); }

void SetUp() override
{
ConfigInitializeNodes(false);
chip::Test::LoopbackMessagingContext::SetUpTestSuite();
chip::Test::LoopbackMessagingContext::SetUp();
}

void TearDown() override { chip::Test::LoopbackMessagingContext::TearDown(); }
};

class PASETestLoopbackTransportDelegate : public Test::LoopbackTransportDelegate
Expand Down

0 comments on commit 2369972

Please sign in to comment.