Skip to content

Commit c419e2f

Browse files
Fix issue related to teardown of some App Tests (#33654)
* Fix issue related to teardown of some App Tests * Update comment Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> --------- Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 896f802 commit c419e2f

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/app/tests/AppTestContext.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ void AppContext::SetUpTestSuite()
4949

5050
void AppContext::TearDownTestSuite()
5151
{
52+
// Some test suites finish with unprocessed work left in the platform manager event queue.
53+
// This can particularly be a problem when this unprocessed work involves reporting engine runs,
54+
// since those can take a while and cause later tests to not reach their queued work before
55+
// their timeouts hit. This is only an issue in setups where all unit tests are compiled into
56+
// a single file (e.g. nRF CI (Zephyr native_posix)).
57+
//
58+
// Work around this issue by doing a DrainAndServiceIO() here to attempt to flush out any queued-up work.
59+
//
60+
// TODO: Solve the underlying issue where test suites leave unprocessed work. Or is this actually
61+
// the right solution?
62+
LoopbackMessagingContext::DrainAndServiceIO();
63+
5264
chip::DeviceLayer::PlatformMgr().Shutdown();
5365
LoopbackMessagingContext::TearDownTestSuite();
5466
}

src/app/tests/BUILD.gn

+2-12
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ chip_test_suite_using_nltest("tests") {
123123
output_name = "libAppTests"
124124

125125
test_sources = [
126+
"TestAclAttribute.cpp",
126127
"TestAclEvent.cpp",
127128
"TestAttributeAccessInterfaceCache.cpp",
128129
"TestAttributePathExpandIterator.cpp",
@@ -151,6 +152,7 @@ chip_test_suite_using_nltest("tests") {
151152
"TestPendingResponseTrackerImpl.cpp",
152153
"TestPowerSourceCluster.cpp",
153154
"TestReadInteraction.cpp",
155+
"TestReportScheduler.cpp",
154156
"TestReportingEngine.cpp",
155157
"TestStatusIB.cpp",
156158
"TestStatusResponseMessage.cpp",
@@ -164,8 +166,6 @@ chip_test_suite_using_nltest("tests") {
164166
test_sources += [ "TestFailSafeContext.cpp" ]
165167
}
166168

167-
test_sources += [ "TestAclAttribute.cpp" ]
168-
169169
# DefaultICDClientStorage assumes that raw AES key is used by the application
170170
if (chip_crypto != "psa") {
171171
test_sources += [ "TestDefaultICDClientStorage.cpp" ]
@@ -189,16 +189,6 @@ chip_test_suite_using_nltest("tests") {
189189
test_sources += [ "TestEventLogging.cpp" ]
190190
}
191191

192-
# The platform manager is not properly clearing queues in test teardown, which results in
193-
# DrainIO calls not being able to run in expected time (5seconds) if unprocessed reported engine
194-
# runs are remaining, causing tests to crash in Open IoT SDK and Zephyr tests since they are
195-
# running all tests in one file. We need to figure out how to properly clean the event queues
196-
# before enabling this test for these platforms.
197-
if (chip_device_platform != "nrfconnect" &&
198-
chip_device_platform != "openiotsdk") {
199-
test_sources += [ "TestReportScheduler.cpp" ]
200-
}
201-
202192
cflags = [ "-Wconversion" ]
203193

204194
public_deps = [

0 commit comments

Comments
 (0)