mirror of https://github.com/libp2p/cpp-libp2p.git
Browse Source
* test - AsioScheduler called onTimer after being destructed Signed-off-by: Alexey-N-Chernyshov <alexey.n.chernyshov@gmail.com> * fix AsioScheduler Signed-off-by: Alexey-N-Chernyshov <alexey.n.chernyshov@gmail.com> * add comment Signed-off-by: Alexey-N-Chernyshov <alexey.n.chernyshov@gmail.com>pull/80/head
Alexey
4 years ago
committed by
GitHub
5 changed files with 59 additions and 1 deletions
@ -0,0 +1,6 @@ |
|||
# |
|||
# Copyright Soramitsu Co., Ltd. All Rights Reserved. |
|||
# SPDX-License-Identifier: Apache-2.0 |
|||
# |
|||
|
|||
add_subdirectory(asio) |
@ -0,0 +1,21 @@ |
|||
# |
|||
# Copyright Soramitsu Co., Ltd. All Rights Reserved. |
|||
# SPDX-License-Identifier: Apache-2.0 |
|||
# |
|||
|
|||
addtest(asio_scheduler_test |
|||
asio_scheduler_test.cpp |
|||
) |
|||
target_link_libraries(asio_scheduler_test |
|||
asio_scheduler |
|||
|
|||
p2p_basic_host |
|||
p2p_default_network |
|||
p2p_peer_repository |
|||
p2p_inmem_address_repository |
|||
p2p_inmem_key_repository |
|||
p2p_inmem_protocol_repository |
|||
p2p_literals |
|||
p2p_kad |
|||
asio_scheduler |
|||
) |
@ -0,0 +1,27 @@ |
|||
/**
|
|||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. |
|||
* SPDX-License-Identifier: Apache-2.0 |
|||
*/ |
|||
|
|||
#include "libp2p/protocol/common/asio/asio_scheduler.hpp" |
|||
|
|||
#include <gtest/gtest.h> |
|||
#include <libp2p/injector/host_injector.hpp> |
|||
|
|||
using libp2p::protocol::Scheduler; |
|||
|
|||
/**
|
|||
* @given Constructs AsioScheduler and schedules on io context and then deletes |
|||
* AsioScheduler |
|||
* @when context is run |
|||
* @then scheduler called and can handle cancellation timer without segfault |
|||
*/ |
|||
TEST(AsioScheduler, Construct) { |
|||
auto injector = libp2p::injector::makeHostInjector(); |
|||
auto context = injector.create<std::shared_ptr<boost::asio::io_context>>(); |
|||
std::shared_ptr<Scheduler> scheduler = |
|||
std::make_shared<libp2p::protocol::AsioScheduler>( |
|||
*context, libp2p::protocol::SchedulerConfig{}); |
|||
scheduler.reset(); |
|||
context->run(); |
|||
} |
Loading…
Reference in new issue