diff --git a/test/time_controller/time_controller_conformance_test.cc b/test/time_controller/time_controller_conformance_test.cc index 10f0e1d724..3d582cad8e 100644 --- a/test/time_controller/time_controller_conformance_test.cc +++ b/test/time_controller/time_controller_conformance_test.cc @@ -92,6 +92,9 @@ TEST_P(SimulatedRealTimeControllerConformanceTest, ThreadPostOrderTest) { thread->PostTask(RTC_FROM_HERE, [&]() { execution_order.Executed(2); }); time_controller->AdvanceTime(TimeDelta::Millis(100)); EXPECT_THAT(execution_order.order(), ElementsAreArray({1, 2})); + // Destroy `thread` before `execution_order` to be sure `execution_order` + // is not accessed on the posted task after it is destroyed. + thread = nullptr; } TEST_P(SimulatedRealTimeControllerConformanceTest, ThreadPostDelayedOrderTest) { @@ -105,6 +108,9 @@ TEST_P(SimulatedRealTimeControllerConformanceTest, ThreadPostDelayedOrderTest) { thread->PostTask(ToQueuedTask([&]() { execution_order.Executed(1); })); time_controller->AdvanceTime(TimeDelta::Millis(600)); EXPECT_THAT(execution_order.order(), ElementsAreArray({1, 2})); + // Destroy `thread` before `execution_order` to be sure `execution_order` + // is not accessed on the posted task after it is destroyed. + thread = nullptr; } TEST_P(SimulatedRealTimeControllerConformanceTest, ThreadPostInvokeOrderTest) { @@ -119,6 +125,9 @@ TEST_P(SimulatedRealTimeControllerConformanceTest, ThreadPostInvokeOrderTest) { thread->Invoke(RTC_FROM_HERE, [&]() { execution_order.Executed(2); }); time_controller->AdvanceTime(TimeDelta::Millis(100)); EXPECT_THAT(execution_order.order(), ElementsAreArray({1, 2})); + // Destroy `thread` before `execution_order` to be sure `execution_order` + // is not accessed on the posted task after it is destroyed. + thread = nullptr; } TEST_P(SimulatedRealTimeControllerConformanceTest, @@ -136,6 +145,9 @@ TEST_P(SimulatedRealTimeControllerConformanceTest, }); time_controller->AdvanceTime(TimeDelta::Millis(100)); EXPECT_THAT(execution_order.order(), ElementsAreArray({1, 2})); + // Destroy `thread` before `execution_order` to be sure `execution_order` + // is not accessed on the posted task after it is destroyed. + thread = nullptr; } TEST_P(SimulatedRealTimeControllerConformanceTest, @@ -158,6 +170,9 @@ TEST_P(SimulatedRealTimeControllerConformanceTest, /*warn_after_ms=*/10'000)); time_controller->AdvanceTime(TimeDelta::Millis(100)); EXPECT_THAT(execution_order.order(), ElementsAreArray({1, 2})); + // Destroy `task_queue` before `execution_order` to be sure `execution_order` + // is not accessed on the posted task after it is destroyed. + task_queue = nullptr; } INSTANTIATE_TEST_SUITE_P(ConformanceTest,