Skip to content

Commit a665539

Browse files
committed
clean up tests and prove this works, also some slight perf improvements
1 parent 9ebb50d commit a665539

6 files changed

Lines changed: 20 additions & 22 deletions

File tree

src/test/btcsignals_tests.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,8 @@ FIXTURE_TEST_CASE(thread_safety, BasicTestingSetup)
159159
for (int i = 0; i < 1000; i++) {
160160
sig0();
161161
}
162-
// Because these calls are purposely happening on both threads at the
163-
// same time, these must be asserts rather than CHECKs to prevent
164-
// a race inside of CHECK itself (writing to the log).
165-
assert(!sig0.empty());
166-
assert(conn0.connected());
162+
CHECK(!sig0.empty());
163+
CHECK(conn0.connected());
167164
});
168165

169166
std::thread extra_increment_injector([&conn0, &sig0, &val] {

src/test/checkqueue_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ FIXTURE_TEST_CASE(test_CheckQueue_FrozenCleanup, CheckQueueTest)
328328
std::vector<FrozenCleanupCheck> vChecks(1);
329329
control.Add(std::move(vChecks));
330330
auto result = control.Complete(); // Hangs here
331-
assert(!result);
331+
CHECK(!result);
332332
});
333333
{
334334
std::unique_lock<std::mutex> l(FrozenCleanupCheck::m);

src/test/cuckoocache_tests.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ void test_cache_erase_parallel(size_t bytes)
230230
size_t end = ntodo*(x+1);
231231
for (uint32_t i = start; i < end; ++i) {
232232
bool contains = set.contains(hashes[i], true);
233-
assert(contains);
233+
if (!contains) {
234+
CHECK(contains);
235+
break;
236+
}
234237
}
235238
});
236239

src/test/scheduler_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ TEST_CASE(singlethreadedscheduler_ordered)
151151
for (int i = 0; i < 100; ++i) {
152152
queue1.insert([i, &counter1]() {
153153
bool expectation = i == counter1++;
154-
assert(expectation);
154+
CHECK(expectation);
155155
});
156156

157157
queue2.insert([i, &counter2]() {
158158
bool expectation = i == counter2++;
159-
assert(expectation);
159+
CHECK(expectation);
160160
});
161161
}
162162

src/test/sock_tests.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <util/threadinterrupt.h>
1111

1212
#include <test/util/framework.hpp>
13-
#include <cassert>
13+
#include <stdexcept>
1414
#include <thread>
1515

1616
using namespace std::chrono_literals;
@@ -163,15 +163,9 @@ FIXTURE_TEST_CASE(recv_until_terminator_limit, BasicTestingSetup)
163163

164164
std::thread receiver([&socks, &timeout, &interrupt]() {
165165
constexpr size_t max_data{10};
166-
bool threw_as_expected{false};
167-
// CHECK_EXCEPTION() writes to some variables shared with the main thread which
168-
// creates a data race. So mimic it manually.
169-
try {
170-
(void)socks.receiver.RecvUntilTerminator('\n', timeout, interrupt, max_data);
171-
} catch (const std::runtime_error& e) {
172-
threw_as_expected = HasReason("too many bytes without a terminator")(e);
173-
}
174-
assert(threw_as_expected);
166+
CHECK_EXCEPTION((void)socks.receiver.RecvUntilTerminator('\n', timeout, interrupt, max_data),
167+
std::runtime_error,
168+
HasReason("too many bytes without a terminator"));
175169
});
176170

177171
REQUIRE_NOTHROW(socks.sender.SendComplete("1234567", timeout, interrupt));

src/test/validation_block_tests.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ FIXTURE_TEST_CASE(processnewblock_signals_ordering, MinerTestingSetup)
206206
for (const auto& block : blocks) {
207207
if (block->vtx.size() == 1) {
208208
bool processed = ProcessNewBlock(*Assert(m_node.chainman), block, true, true, &ignored);
209-
assert(processed);
209+
CHECK(processed);
210210
}
211211
}
212212
});
@@ -322,12 +322,16 @@ FIXTURE_TEST_CASE(mempool_locks_reorg, MinerTestingSetup)
322322
// be atomic. So the caller assumes that the returned mempool
323323
// is consistent. That is, it has all txs that were there
324324
// before the reorg.
325-
assert(m_node.mempool->size() == txs.size());
325+
const auto mempool_size{m_node.mempool->size()};
326+
if (mempool_size != txs.size()) {
327+
CHECK(mempool_size == txs.size());
328+
break;
329+
}
326330
continue;
327331
}
328332
LOCK(cs_main);
329333
// We are done with the reorg, so the tip must have changed
330-
assert(tip_init != m_node.chainman->ActiveChain().Tip()->GetBlockHash());
334+
CHECK(tip_init != m_node.chainman->ActiveChain().Tip()->GetBlockHash());
331335
}};
332336

333337
// Submit the reorg in this thread to invalidate and remove the txs from the tx pool

0 commit comments

Comments
 (0)