Do thread cleanup within the same thread context.

This commit is contained in:
rakshasa
2025-05-30 10:16:03 +02:00
committed by Jari Sundell
parent de6c48ca3f
commit 2d565d1c80
7 changed files with 119 additions and 24 deletions
+43 -10
View File
@@ -2,26 +2,24 @@
#include "test_main_thread.h"
#include "globals.h"
#include <signal.h>
#include "test/helpers/mock_function.h"
#include "torrent/exceptions.h"
#include "torrent/poll.h"
#include "torrent/net/resolver.h"
#include "torrent/utils/log.h"
#include "torrent/utils/scheduler.h"
std::unique_ptr<TestMainThread>
TestMainThread::create() {
// Needs to be called before Thread is created.
mock_redirect_defaults();
auto thread = new TestMainThread();
return std::unique_ptr<TestMainThread>(thread);
return std::unique_ptr<TestMainThread>(new TestMainThread());
}
TestMainThread::TestMainThread() {}
TestMainThread::~TestMainThread() {
m_self = nullptr;
std::unique_ptr<TestMainThread>
TestMainThread::create_with_mock() {
return std::unique_ptr<TestMainThread>(new TestMainThread());
}
void
@@ -34,6 +32,10 @@ TestMainThread::init_thread() {
init_thread_local();
}
void
TestMainThread::cleanup_thread() {
}
void
TestMainThread::call_events() {
process_callbacks();
@@ -41,5 +43,36 @@ TestMainThread::call_events() {
std::chrono::microseconds
TestMainThread::next_timeout() {
return std::chrono::microseconds(10min);
return 10min;
}
void
TestFixtureWithMainThread::setUp() {
test_fixture::setUp();
m_main_thread = TestMainThread::create();
m_main_thread->init_thread();
}
void
TestFixtureWithMainThread::tearDown() {
m_main_thread.reset();
test_fixture::tearDown();
}
void
TestFixtureWithMockAndMainThread::setUp() {
test_fixture::setUp();
m_main_thread = TestMainThread::create_with_mock();
m_main_thread->init_thread();
}
void
TestFixtureWithMockAndMainThread::tearDown() {
m_main_thread.reset();
test_fixture::tearDown();
}