rockerbacon / assertions-test

Test framework for the Assertions C++ Framework
GNU General Public License v3.0
0 stars 0 forks source link

Scope Confinement and binary test results break when multithreaded method segfaults #3

Open rockerbacon opened 4 years ago

rockerbacon commented 4 years ago

Description

#include <test.h>
#include <thread>

tests {
    test_suite("when a thread created inside a test_case block segfaults") {
        test_case("the test is interrupted abruptly") {
            std::thread([]{
                int* invalid_ptr = nullptr;
                *invalid_ptr = 3;
            }).join();
        };
        test_case("other test cases get stuck in whichever state they where on") {
            using namespace std::literals::chrono_literals;
            std::this_thread::sleep_for(2s);
        };
    }
}

Cause

The low level error handler is configured on a per-thread basis whenever a new test is queued for execution. Since the error handler was never configured for the thread created inside the test case, it has no way of keeping the program from terminating.

rockerbacon commented 4 years ago

Even though the changes introduced in #12 fixed the scenario for anything using std::future, the problem still persists when using std::thread directly. This occurs because std::thread does not rethrow exceptions raised inside of it.