Skip to content

Commit fab6d06

Browse files
author
MarcoFalke
committed
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
1 parent 6413980 commit fab6d06

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/test/validationinterface_tests.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,42 @@
1212

1313
BOOST_FIXTURE_TEST_SUITE(validationinterface_tests, TestingSetup)
1414

15+
/**
16+
struct TestSubscriberNoop final : public CValidationInterface {
17+
void BlockChecked(const CBlock&, const BlockValidationState&) override {}
18+
};
19+
20+
BOOST_AUTO_TEST_CASE(unregister_validation_interface_race)
21+
{
22+
std::atomic<bool> generate{true};
23+
24+
// Start thread to generate notifications
25+
std::thread gen{[&] {
26+
const CBlock block_dummy;
27+
const BlockValidationState state_dummy;
28+
while (generate) {
29+
GetMainSignals().BlockChecked(block_dummy, state_dummy);
30+
}
31+
}};
32+
33+
// Start thread to consume notifications
34+
std::thread sub{[&] {
35+
// keep going for about 1 sec, which is 250k iterations
36+
for (int i = 0; i < 250000; i++) {
37+
TestSubscriberNoop sub{};
38+
RegisterValidationInterface(&sub);
39+
UnregisterValidationInterface(&sub);
40+
}
41+
// tell the other thread we are done
42+
generate = false;
43+
}};
44+
45+
gen.join();
46+
sub.join();
47+
BOOST_CHECK(!generate);
48+
}
49+
*/
50+
1551
class TestInterface : public CValidationInterface
1652
{
1753
public:

0 commit comments

Comments
 (0)