2017-05-16 07:40:18 +00:00
|
|
|
/++ dub.sdl:
|
|
|
|
name "tests"
|
|
|
|
description "TCP disconnect task issue"
|
|
|
|
dependency "vibe-core" path="../"
|
|
|
|
+/
|
|
|
|
module tests;
|
|
|
|
|
|
|
|
import vibe.core.core;
|
|
|
|
import vibe.core.net;
|
|
|
|
import core.time : msecs;
|
|
|
|
import vibe.core.log;
|
|
|
|
|
2017-07-18 09:55:39 +00:00
|
|
|
ubyte[] buf;
|
2017-05-16 07:40:18 +00:00
|
|
|
|
2017-07-18 09:55:39 +00:00
|
|
|
void performTest(bool reverse)
|
|
|
|
{
|
|
|
|
auto l = listenTCP(11375, (conn) {
|
2017-05-16 07:40:18 +00:00
|
|
|
bool read_ex = false;
|
|
|
|
bool write_ex = false;
|
|
|
|
auto rt = runTask!TCPConnection((conn) {
|
|
|
|
try {
|
|
|
|
conn.read(buf);
|
|
|
|
assert(false, "Expected read() to throw an exception.");
|
|
|
|
} catch (Exception) {
|
|
|
|
read_ex = true;
|
|
|
|
conn.close();
|
|
|
|
logInfo("read out");
|
|
|
|
} // expected
|
|
|
|
}, conn);
|
|
|
|
auto wt = runTask!TCPConnection((conn) {
|
2017-07-18 09:55:39 +00:00
|
|
|
sleep(reverse ? 100.msecs : 20.msecs); // give the connection time to establish
|
2017-05-16 07:40:18 +00:00
|
|
|
try {
|
|
|
|
conn.write(buf);
|
2017-07-18 09:55:39 +00:00
|
|
|
assert(false, "Expected write() to throw an exception.");
|
2017-05-16 07:40:18 +00:00
|
|
|
} catch (Exception) {
|
|
|
|
write_ex = true;
|
|
|
|
conn.close();
|
|
|
|
logInfo("write out");
|
|
|
|
} // expected
|
|
|
|
}, conn);
|
|
|
|
|
|
|
|
rt.join();
|
|
|
|
wt.join();
|
|
|
|
assert(read_ex, "No read exception thrown");
|
|
|
|
assert(write_ex, "No write exception thrown");
|
2017-07-18 09:55:39 +00:00
|
|
|
logInfo("Test has finished successfully.");
|
|
|
|
exitEventLoop();
|
2017-05-16 07:40:18 +00:00
|
|
|
}, "127.0.0.1");
|
|
|
|
|
|
|
|
runTask({
|
|
|
|
try {
|
|
|
|
auto conn = connectTCP("127.0.0.1", 11375);
|
2017-07-18 09:55:39 +00:00
|
|
|
sleep(reverse ? 20.msecs : 100.msecs);
|
2017-05-16 07:40:18 +00:00
|
|
|
conn.close();
|
|
|
|
} catch (Exception e) assert(false, e.msg);
|
|
|
|
});
|
|
|
|
|
2017-07-18 09:55:39 +00:00
|
|
|
runEventLoop();
|
|
|
|
|
|
|
|
l.stopListening();
|
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
setTimer(10000.msecs, { assert(false, "Test has hung."); });
|
|
|
|
buf = new ubyte[512*1024*1024];
|
2017-05-16 07:40:18 +00:00
|
|
|
|
2017-07-18 09:55:39 +00:00
|
|
|
performTest(false);
|
|
|
|
performTest(true);
|
2017-05-16 07:40:18 +00:00
|
|
|
}
|