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>
diff --git a/src/app/tests/AppTestContext.cpp b/src/app/tests/AppTestContext.cpp
index eca7a2d..ff1154d 100644
--- a/src/app/tests/AppTestContext.cpp
+++ b/src/app/tests/AppTestContext.cpp
@@ -49,6 +49,18 @@
 
 void AppContext::TearDownTestSuite()
 {
+    // Some test suites finish with unprocessed work left in the platform manager event queue.
+    // This can particularly be a problem when this unprocessed work involves reporting engine runs,
+    // since those can take a while and cause later tests to not reach their queued work before
+    // their timeouts hit.  This is only an issue in setups where all unit tests are compiled into
+    // a single file (e.g. nRF CI (Zephyr native_posix)).
+    //
+    // Work around this issue by doing a DrainAndServiceIO() here to attempt to flush out any queued-up work.
+    //
+    // TODO: Solve the underlying issue where test suites leave unprocessed work.  Or is this actually
+    // the right solution?
+    LoopbackMessagingContext::DrainAndServiceIO();
+
     chip::DeviceLayer::PlatformMgr().Shutdown();
     LoopbackMessagingContext::TearDownTestSuite();
 }
diff --git a/src/app/tests/BUILD.gn b/src/app/tests/BUILD.gn
index df6737a..2840877 100644
--- a/src/app/tests/BUILD.gn
+++ b/src/app/tests/BUILD.gn
@@ -123,6 +123,7 @@
   output_name = "libAppTests"
 
   test_sources = [
+    "TestAclAttribute.cpp",
     "TestAclEvent.cpp",
     "TestAttributeAccessInterfaceCache.cpp",
     "TestAttributePathExpandIterator.cpp",
@@ -151,6 +152,7 @@
     "TestPendingResponseTrackerImpl.cpp",
     "TestPowerSourceCluster.cpp",
     "TestReadInteraction.cpp",
+    "TestReportScheduler.cpp",
     "TestReportingEngine.cpp",
     "TestStatusIB.cpp",
     "TestStatusResponseMessage.cpp",
@@ -164,8 +166,6 @@
     test_sources += [ "TestFailSafeContext.cpp" ]
   }
 
-  test_sources += [ "TestAclAttribute.cpp" ]
-
   # DefaultICDClientStorage assumes that raw AES key is used by the application
   if (chip_crypto != "psa") {
     test_sources += [ "TestDefaultICDClientStorage.cpp" ]
@@ -189,16 +189,6 @@
     test_sources += [ "TestEventLogging.cpp" ]
   }
 
-  # The platform manager is not properly clearing queues in test teardown, which results in
-  # DrainIO calls not being able to run in expected time (5seconds) if unprocessed reported engine
-  # runs are remaining, causing tests to crash in Open IoT SDK and Zephyr tests since they are
-  # running all tests in one file. We need to figure out how to properly clean the event queues
-  # before enabling this test for these platforms.
-  if (chip_device_platform != "nrfconnect" &&
-      chip_device_platform != "openiotsdk") {
-    test_sources += [ "TestReportScheduler.cpp" ]
-  }
-
   cflags = [ "-Wconversion" ]
 
   public_deps = [