Adjust transfer methods behaviour when interrupted

A transer is attempted even if the transport has been interrupted
(with a timeout). When the timeout is reached, transfer methods will
return TransferResult::interrupted (-3).
This commit is contained in:
Alexey Rybalchenko
2020-09-15 17:18:53 +02:00
committed by Dennis Klein
parent 5e97d85956
commit 6932f88c84
8 changed files with 169 additions and 91 deletions

View File

@@ -7,9 +7,16 @@
********************************************************************************/
#include "runner.h"
#include <FairMQChannel.h>
#include <FairMQLogger.h>
#include <FairMQTransportFactory.h>
#include <fairmq/ProgOptions.h>
#include <fairmq/Tools.h>
#include <gtest/gtest.h>
#include <chrono>
#include <sstream> // std::stringstream
#include <thread>
namespace
{
@@ -18,6 +25,12 @@ using namespace std;
using namespace fair::mq::test;
using namespace fair::mq::tools;
void delayedInterruptor(FairMQTransportFactory& transport)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
transport.Interrupt();
}
auto RunTransferTimeout(string transport) -> void
{
size_t session{fair::mq::tools::UuidHash()};
@@ -31,6 +44,28 @@ auto RunTransferTimeout(string transport) -> void
exit(res.exit_code);
}
void InterruptTransfer(const string& transport, const string& _address)
{
size_t session{fair::mq::tools::UuidHash()};
std::string address(fair::mq::tools::ToString(_address, "_", transport));
fair::mq::ProgOptions config;
config.SetProperty<string>("session", to_string(session));
auto factory = FairMQTransportFactory::CreateTransportFactory(transport, fair::mq::tools::Uuid(), &config);
FairMQChannel pull{"Pull", "pull", factory};
pull.Bind(address);
FairMQMessagePtr msg(pull.NewMessage());
auto t = thread(delayedInterruptor, ref(*factory));
auto result = pull.Receive(msg);
t.join();
ASSERT_EQ(result, static_cast<int>(fair::mq::TransferResult::interrupted));
}
TEST(TransferTimeout, zeromq)
{
EXPECT_EXIT(RunTransferTimeout("zeromq"), ::testing::ExitedWithCode(0), "Transfer timeout test successfull");
@@ -41,4 +76,14 @@ TEST(TransferTimeout, shmem)
EXPECT_EXIT(RunTransferTimeout("shmem"), ::testing::ExitedWithCode(0), "Transfer timeout test successfull");
}
TEST(InterruptTransfer, zeromq)
{
InterruptTransfer("zeromq", "ipc://test_interrupt_transfer");
}
TEST(InterruptTransfer, shmem)
{
InterruptTransfer("shmem", "ipc://test_interrupt_transfer");
}
} // namespace