Skip to content

Commit

Permalink
Add immediate read test and skip final write after close.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Nov 11, 2015
1 parent 429ee29 commit 9c2b8e8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/tcp/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum port = 12675;

enum Test {
receive,
receiveExisting,
timeout,
noTimeout,
noTimeoutCompat,
Expand All @@ -35,6 +36,12 @@ void test()
assert(cast(Duration)sw.peek < 2.seconds); // should receive something instantly
assert(conn.readLine() == "receive");
break;
case Test.receiveExisting:
assert(conn.waitForData(2.seconds) == true);
// TODO: validate that waitForData didn't yield!
assert(cast(Duration)sw.peek < 2.seconds); // should receive something instantly
assert(conn.readLine() == "receiveExisting");
break;
case Test.timeout:
assert(conn.waitForData(2.seconds) == false);
assert(cast(Duration)sw.peek > 1900.msecs); // should wait for at least 2 seconds
Expand All @@ -54,7 +61,7 @@ void test()
assert(conn.waitForData(2.seconds) == false);
assert(cast(Duration)sw.peek < 2.seconds); // connection should be closed instantly
assert(!conn.connected);
break;
return;
}
conn.write("ok\r\n");
}
Expand All @@ -68,6 +75,11 @@ void test()
conn.write("receive\r\n");
assert(conn.readLine() == "ok");

test = Test.receiveExisting;
conn.write("next\r\nreceiveExisting\r\n");
assert(conn.readLine() == "continue");
assert(conn.readLine() == "ok");

test = Test.timeout;
conn.write("next\r\n");
assert(conn.readLine() == "continue");
Expand Down

0 comments on commit 9c2b8e8

Please sign in to comment.