Skip to content

Commit f0df2d1

Browse files
committed
ensure proper init and shutdown during tests as these contexts and registries are now sensitive
1 parent 8af034f commit f0df2d1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/app/server-cluster/testing/TestServerClusterContext.h

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
#pragma once
1818

19+
#include "app/data-model-provider/Context.h"
1920
#include <app/data-model-provider/ActionContext.h>
2021
#include <app/data-model-provider/Provider.h>
2122
#include <app/server-cluster/ServerClusterContext.h>
@@ -74,6 +75,8 @@ class TestServerClusterContext
7475
LogOnlyEvents & EventsGenerator() { return mTestEventsGenerator; }
7576
TestProviderChangeListener & ChangeListener() { return mTestDataModelChangeListener; }
7677
TestPersistentStorageDelegate & StorageDelegate() { return mTestStorage; }
78+
app::DataModel::InteractionModelContext &ImContext() { return mTestContext; }
79+
7780

7881
private:
7982
NullActionContext mNullActionContext;

src/data-model-providers/codegen/tests/TestCodegenModelViaMocks.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <data-model-providers/codegen/tests/EmberInvokeOverride.h>
2020
#include <data-model-providers/codegen/tests/EmberReadWriteOverride.h>
2121

22+
#include <app/server-cluster/testing/TestServerClusterContext.h>
2223
#include <access/AccessControl.h>
2324
#include <access/SubjectDescriptor.h>
2425
#include <app-common/zap-generated/attribute-type.h>
@@ -2599,9 +2600,15 @@ static CHIP_ERROR ReadU32Attribute(DataModel::Provider & provider, const Concret
25992600

26002601
TEST_F(TestCodegenModelViaMocks, ServerClusterInterfacesRegistration)
26012602
{
2603+
TestServerClusterContext testContext;
2604+
26022605
UseMockNodeConfig config(gTestNodeConfig);
26032606
CodegenDataModelProviderWithContext model;
26042607

2608+
2609+
model.SetPersistentStorageDelegate(&testContext.StorageDelegate());
2610+
ASSERT_EQ(model.Startup(testContext.ImContext()), CHIP_NO_ERROR);
2611+
26052612
const ConcreteClusterPath kTestClusterPath(kMockEndpoint1, MockClusterId(2));
26062613

26072614
FakeDefaultServerCluster fakeClusterServer(kTestClusterPath);
@@ -2670,13 +2677,21 @@ TEST_F(TestCodegenModelViaMocks, ServerClusterInterfacesRegistration)
26702677
std::optional<ActionReturnStatus> result = model.WriteAttribute(test.GetRequest(), decoder);
26712678
ASSERT_TRUE(result.has_value() && result->GetUnderlyingError() == CHIP_ERROR_INCORRECT_STATE);
26722679
}
2680+
2681+
model.Registry().Unregister(kTestClusterPath);
2682+
model.Shutdown();
26732683
}
26742684

26752685
TEST_F(TestCodegenModelViaMocks, ServerClusterInterfacesListClusters)
26762686
{
2687+
TestServerClusterContext testContext;
2688+
26772689
UseMockNodeConfig config(gTestNodeConfig);
26782690
CodegenDataModelProviderWithContext model;
26792691

2692+
model.SetPersistentStorageDelegate(&testContext.StorageDelegate());
2693+
ASSERT_EQ(model.Startup(testContext.ImContext()), CHIP_NO_ERROR);
2694+
26802695
// will register a fake cluster server which overrides the cluster data version
26812696
// once registered
26822697
const ConcreteClusterPath kTestClusterPath(kMockEndpoint1, MockClusterId(2));
@@ -2743,4 +2758,7 @@ TEST_F(TestCodegenModelViaMocks, ServerClusterInterfacesListClusters)
27432758
}
27442759
}
27452760
EXPECT_TRUE(updatedClusterFound);
2761+
2762+
model.Registry().Unregister(kTestClusterPath);
2763+
model.Shutdown();
27462764
}

0 commit comments

Comments
 (0)