void BasicThread::ForceCoreThreadReidentify(void) { for(const auto& ctxt : ContextEnumerator(AutoGlobalContext())) { auto threadListCpy = ctxt->CopyBasicThreadList(); for(auto q = threadListCpy.begin(); q != threadListCpy.end(); q++) (**q).SetCurrentThreadName(); } }
void AutowiringEnclosure::OnTestEnd(const testing::TestInfo& info) { // Verify we can grab the test case back out and that the pointer is correct: Autowired<TestInfoProxy> ti; Autowired<AutowiringEnclosureExceptionFilter> ecef; auto ctxt = ecef ? ecef->GetContext() : nullptr; // Unconditionally reset the global context as the current context AutoGlobalContext()->SetCurrent(); // Global initialization tests are special, we don't bother checking closure principle on them: if(!strcmp("GlobalInitTest", info.test_case_name())) return; // Need to make sure we got back our exception filter before continuing: ASSERT_TRUE(ecef.IsAutowired()) << "Failed to find the enclosed context exception filter; unit test may have incorrectly reset the enclosing context before returning"; // Now try to tear down the test context enclosure: ctxt->SignalShutdown(); // Do not allow teardown to take more than 250 milliseconds or so if(!ctxt->Wait(std::chrono::milliseconds(250))) { // Critical error--took too long to tear down assert(false); } static const char s_autothrow[] = "AUTOTHROW_"; if(!strncmp(s_autothrow, info.name(), ARRAYCOUNT(s_autothrow) - 1)) // Throw expected, end here return; // If an exception occurred somewhere, report it: ASSERT_FALSE(ecef->m_excepted) << "An unhandled exception occurred in this context" << std::endl << "[" << (ecef->m_ti ? ecef->m_ti->name() : "unknown") << "] " << ecef->m_what; }
TEST_F(ContextEnumeratorTest, VerifyComplexEnumeration) { std::shared_ptr<CoreContext> firstNamed, secondNamed; AutoCreateContext firstContext; { CurrentContextPusher pshr(firstContext); AutoCreateContextT<NamedContext> named; firstNamed = named; } AutoCreateContext secondContext; { CurrentContextPusher pshr(secondContext); AutoCreateContextT<NamedContext> named; secondNamed = named; } // Verify there is only one context under the first context int firstCount = 0; for(auto ctxt : ContextEnumeratorT<NamedContext>(firstContext)) { firstCount++; ASSERT_EQ(ctxt, firstNamed); ASSERT_EQ(ctxt->GetParentContext(), firstContext); } ASSERT_EQ(firstCount, 1) << "Expected exactly one context in the parent context, found " << firstCount; // Verify there is only one context under the second context int secondCount = 0; for(auto ctxt : ContextEnumeratorT<NamedContext>(secondContext)) { secondCount++; ASSERT_EQ(ctxt, secondNamed); ASSERT_EQ(ctxt->GetParentContext(), secondContext); } ASSERT_EQ(secondCount, 1) << "Expected exactly one context in the parent context, found " << secondCount; // Verify global context structure int globalCount = 0; for(auto ctxt : ContextEnumeratorT<NamedContext>(AutoGlobalContext())) { globalCount++; } ASSERT_EQ(globalCount, 2) << "Expected exactly one context in the parent context, found " << globalCount; }