TEST(TcpListenerTest, tcpListener1) { Dispatcher dispatcher; Event event(dispatcher); TcpListener listener(dispatcher, Ipv4Address("127.0.0.1"), 6666); dispatcher.spawn([&]() { TcpConnector connector(dispatcher); connector.connect(Ipv4Address("127.0.0.1"), 6666); event.set(); }); listener.stop(); listener.start(); listener.accept(); listener.stop(); listener.start(); event.wait(); }
TEST(TcpListenerTest, tcpListener3) { bool stopped = false; Dispatcher dispatcher; Event event(dispatcher); TcpListener listener(dispatcher, Ipv4Address("127.0.0.1"), 6666); dispatcher.spawn([&]() { Timer(dispatcher).sleep(std::chrono::milliseconds(10)); listener.stop(); event.set(); }); try { listener.accept(); } catch (InterruptedException&) { stopped = true; } event.wait(); ASSERT_TRUE(stopped); }