diff --git a/tensorpipe/test/transport/connection_test.cc b/tensorpipe/test/transport/connection_test.cc index af60258cc..a82725a62 100644 --- a/tensorpipe/test/transport/connection_test.cc +++ b/tensorpipe/test/transport/connection_test.cc @@ -245,3 +245,39 @@ TEST_P(TransportTest, DISABLED_Connection_EmptyBuffer) { peers_->join(PeerGroup::kClient); }); } + +TEST_P(TransportTest, Connection_SpamAtClosing) { + using namespace std::chrono_literals; + + std::shared_ptr ctx = GetParam()->getContext(); + ctx->setId("loopback"); + + std::string addr = GetParam()->defaultAddr(); + std::shared_ptr listener = ctx->listen(addr); + + std::atomic stopSpamming{false}; + std::function spam = [&]() { + if (stopSpamming) { + return; + } + std::shared_ptr conn = ctx->connect(addr); + conn->read( + [&](const Error& error, const void* /* unused */, size_t /* unused */) { + EXPECT_TRUE(error); + spam(); + }); + conn->close(); + }; + + spam(); + + std::this_thread::sleep_for(10ms); + + ctx->close(); + + std::this_thread::sleep_for(10ms); + + stopSpamming = true; + + ctx->join(); +}