Skip to content

Commit

Permalink
Fix mock leaks (#1831)
Browse files Browse the repository at this point in the history
* refactor: replace waiting on promise by waiting on barrier

Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
  • Loading branch information
xDimon authored Oct 5, 2023
1 parent f93edce commit b3e1a14
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions test/testutil/asio_wait.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef KAGOME_TEST_TESTUTIL_ASIO_WAIT_HPP
#define KAGOME_TEST_TESTUTIL_ASIO_WAIT_HPP
#pragma once

#include <boost/asio/io_context.hpp>
#include <future>

#include <barrier>

namespace testutil {

/**
* Wait for all queued tasks.
*/
void wait(boost::asio::io_context &io) {
std::promise<void> promise;
auto future = promise.get_future();
io.post([promise{std::make_shared<decltype(promise)>(std::move(promise))}] {
promise->set_value();
});
future.get();
std::barrier barrier(2);
io.post([&] { barrier.arrive_and_wait(); });
barrier.arrive_and_wait();
}
} // namespace testutil

#endif // KAGOME_TEST_TESTUTIL_ASIO_WAIT_HPP
} // namespace testutil

0 comments on commit b3e1a14

Please sign in to comment.