Break the dependency between tests that use MessagingContext (#33588)
* Fix dependency between tests
* Restyled by clang-format
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/messaging/tests/MessagingContext.cpp b/src/messaging/tests/MessagingContext.cpp
index 61565da..909bc90 100644
--- a/src/messaging/tests/MessagingContext.cpp
+++ b/src/messaging/tests/MessagingContext.cpp
@@ -58,7 +58,7 @@
ReturnErrorOnFailure(mExchangeManager.Init(&mSessionManager));
ReturnErrorOnFailure(mMessageCounterManager.Init(&mExchangeManager));
- if (sInitializeNodes)
+ if (mInitializeNodes)
{
ReturnErrorOnFailure(CreateAliceFabric());
ReturnErrorOnFailure(CreateBobFabric());
@@ -112,8 +112,6 @@
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)
diff --git a/src/messaging/tests/MessagingContext.h b/src/messaging/tests/MessagingContext.h
index bd9b0b9..51525f9 100644
--- a/src/messaging/tests/MessagingContext.h
+++ b/src/messaging/tests/MessagingContext.h
@@ -101,7 +101,7 @@
~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);
@@ -178,7 +178,7 @@
System::Layer & GetSystemLayer() { return mIOContext->GetSystemLayer(); }
private:
- static bool sInitializeNodes;
+ bool mInitializeNodes = true;
bool mInitialized;
FabricTable mFabricTable;
diff --git a/src/protocols/secure_channel/tests/TestCASESession.cpp b/src/protocols/secure_channel/tests/TestCASESession.cpp
index 5fc6a37..68d6ddd 100644
--- a/src/protocols/secure_channel/tests/TestCASESession.cpp
+++ b/src/protocols/secure_channel/tests/TestCASESession.cpp
@@ -64,6 +64,13 @@
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)
@@ -329,7 +336,6 @@
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
diff --git a/src/protocols/secure_channel/tests/TestPASESession.cpp b/src/protocols/secure_channel/tests/TestPASESession.cpp
index d610b30..896f721 100644
--- a/src/protocols/secure_channel/tests/TestPASESession.cpp
+++ b/src/protocols/secure_channel/tests/TestPASESession.cpp
@@ -89,11 +89,16 @@
{
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