mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
test: Add unregister_validation_interface_race test
This commit is (intentionally) adding a broken test. The test is broken because it registering a subscriber object that can go out of scope while events are still being sent. To run the broken test and reproduce the bug: - Remove comment /** and */ - ./configure --with-sanitizers=address - export ASAN_OPTIONS=detect_leaks=0 - make - while ./src/test/test_bitcoin -t validationinterface_tests/unregister_validation_interface_race --catch_system_errors=no ; do true; done
This commit is contained in:
parent
64139803f1
commit
fab6d060ce
1 changed files with 36 additions and 0 deletions
|
@ -12,6 +12,42 @@
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_SUITE(validationinterface_tests, TestingSetup)
|
BOOST_FIXTURE_TEST_SUITE(validationinterface_tests, TestingSetup)
|
||||||
|
|
||||||
|
/**
|
||||||
|
struct TestSubscriberNoop final : public CValidationInterface {
|
||||||
|
void BlockChecked(const CBlock&, const BlockValidationState&) override {}
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(unregister_validation_interface_race)
|
||||||
|
{
|
||||||
|
std::atomic<bool> generate{true};
|
||||||
|
|
||||||
|
// Start thread to generate notifications
|
||||||
|
std::thread gen{[&] {
|
||||||
|
const CBlock block_dummy;
|
||||||
|
const BlockValidationState state_dummy;
|
||||||
|
while (generate) {
|
||||||
|
GetMainSignals().BlockChecked(block_dummy, state_dummy);
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
|
||||||
|
// Start thread to consume notifications
|
||||||
|
std::thread sub{[&] {
|
||||||
|
// keep going for about 1 sec, which is 250k iterations
|
||||||
|
for (int i = 0; i < 250000; i++) {
|
||||||
|
TestSubscriberNoop sub{};
|
||||||
|
RegisterValidationInterface(&sub);
|
||||||
|
UnregisterValidationInterface(&sub);
|
||||||
|
}
|
||||||
|
// tell the other thread we are done
|
||||||
|
generate = false;
|
||||||
|
}};
|
||||||
|
|
||||||
|
gen.join();
|
||||||
|
sub.join();
|
||||||
|
BOOST_CHECK(!generate);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
class TestInterface : public CValidationInterface
|
class TestInterface : public CValidationInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue