mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-28 18:19:31 +01:00
test: cleanup, use HasReason in threadpool_tests.cpp
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <common/system.h>
|
||||
#include <logging.h>
|
||||
#include <random.h>
|
||||
#include <test/util/common.h>
|
||||
#include <util/string.h>
|
||||
#include <util/threadpool.h>
|
||||
#include <util/time.h>
|
||||
@@ -164,21 +165,17 @@ BOOST_AUTO_TEST_CASE(task_exception_propagates_to_future)
|
||||
ThreadPool threadPool(POOL_NAME);
|
||||
threadPool.Start(NUM_WORKERS_DEFAULT);
|
||||
|
||||
int num_tasks = 5;
|
||||
std::string err_msg{"something wrong happened"};
|
||||
const auto make_err{[&](size_t n) { return strprintf("error on thread #%s", n); }};
|
||||
|
||||
const int num_tasks = 5;
|
||||
std::vector<std::future<void>> futures;
|
||||
futures.reserve(num_tasks);
|
||||
for (int i = 0; i < num_tasks; i++) {
|
||||
futures.emplace_back(Submit(threadPool, [err_msg, i]() {
|
||||
throw std::runtime_error(err_msg + util::ToString(i));
|
||||
}));
|
||||
futures.emplace_back(Submit(threadPool, [&make_err, i] { throw std::runtime_error(make_err(i)); }));
|
||||
}
|
||||
|
||||
for (int i = 0; i < num_tasks; i++) {
|
||||
BOOST_CHECK_EXCEPTION(futures.at(i).get(), std::runtime_error, [&](const std::runtime_error& e) {
|
||||
BOOST_CHECK_EQUAL(e.what(), err_msg + util::ToString(i));
|
||||
return true;
|
||||
});
|
||||
BOOST_CHECK_EXCEPTION(futures[i].get(), std::runtime_error, HasReason{make_err(i)});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user