Permalink
Browse files

Added tests for possible timeout related problems

  • Loading branch information...
1 parent 5c99b82 commit ef215fdd245e7932736769cb0033a6cd6663bb3d @lizmat lizmat committed Jul 23, 2013
Showing with 39 additions and 12 deletions.
  1. +39 −12 S32-io/IO-Socket-INET.t
View
@@ -1,15 +1,16 @@
use v6;
use Test;
-plan 21;
+plan 41;
-my $last = time;
+diag "{elapsed} starting tests";
+my $elapsed;
sub elapsed {
- return "[{ time - $last }s]";
+ state $last = time;
LEAVE $last = time;
+ return "[{ $elapsed = time - $last }s]";
}
-
-diag "{elapsed} starting tests";
+my $toolong = 5;
# L<S32::IO/IO::Socket::INET>
@@ -74,6 +75,7 @@ if $*OS eq any <linux darwin solaris MSWin32> { # please add more valid OS names
#warn "TEST 2 $received";
$expected = "echo '0123456789abcdefghijklmnopqrstuvwxyz' received\n";
is $received, $expected, "{elapsed} echo server and client";
+ nok $elapsed > $toolong, "took too long 1";
# test 3 does discard protocol - Internet RFC 863
if $is-win {
@@ -84,6 +86,7 @@ if $*OS eq any <linux darwin solaris MSWin32> { # please add more valid OS names
#warn "TEST 3 $received";
$expected = "discard '' received\n";
is $received, $expected, "{elapsed} discard server and client";
+ nok $elapsed > $toolong, "took too long 2";
# test 4 tests recv with a parameter
if $is-win {
@@ -94,16 +97,23 @@ if $*OS eq any <linux darwin solaris MSWin32> { # please add more valid OS names
$expected = $received.split("\n");
my $i = 0;
is $expected[$i++], '0123456', "{elapsed} received first 7 characters";
+ nok $elapsed > $toolong, "took too long 3";
is $expected[$i++], '789', "{elapsed} received next 3 characters";
+ nok $elapsed > $toolong, "took too long 4";
is $expected[$i++], 'abcdefghijklmnopqrstuvwxyz', "{elapsed} remaining 26 were buffered";
+ nok $elapsed > $toolong, "took too long 5";
# Multibyte characters
# RT #115862
is $expected[$i], chr(0xbeef), "{elapsed} received {chr 0xbeef}";
+ nok $elapsed > $toolong, "took too long 6";
$i++;
is $expected[$i++], 1, "{elapsed} ... which is 1 character";
+ nok $elapsed > $toolong, "took too long 7";
is $expected[$i++], 1, "{elapsed} received another character";
+ nok $elapsed > $toolong, "took too long 8";
# RT #115862
is $expected[$i], chr(0xbabe), "{elapsed} combined the bytes form {chr 0xbabe}";
+ nok $elapsed > $toolong, "took too long 9";
$i++;
# test 5 tests get()
@@ -115,13 +125,25 @@ if $*OS eq any <linux darwin solaris MSWin32> { # please add more valid OS names
$expected = $received.split("\n");
$i = 0;
is $expected[$i++], "'Twas brillig, and the slithy toves",
- "{elapsed} get() with default separator";
- is $expected[$i++], 'Did gyre and gimble in the wabe;', "{elapsed} default separator";
- is $expected[$i++], 'All mimsy were the borogoves,', "{elapsed} \\r\\n separator";
- is $expected[$i++], 'And the mome raths outgrabe', "{elapsed} . as a separator";
- is $expected[$i++], 'O frabjous day', "{elapsed} ! separator not at end of string";
- is $expected[$i++], ' Callooh', "{elapsed} Multiple separators not at end of string";
- is $expected[$i++], ' Callay', "{elapsed} ! separator at end of string";
+ "{elapsed} get() with default separator";
+ nok $elapsed > $toolong, "took too long 10";
+ is $expected[$i++], 'Did gyre and gimble in the wabe;',
+ "{elapsed} default separator";
+ nok $elapsed > $toolong, "took too long 11";
+ is $expected[$i++], 'All mimsy were the borogoves,',
+ "{elapsed} \\r\\n separator";
+ nok $elapsed > $toolong, "took too long 12";
+ is $expected[$i++], 'And the mome raths outgrabe',
+ "{elapsed} . as a separator";
+ nok $elapsed > $toolong, "took too long 13";
+ is $expected[$i++], 'O frabjous day',
+ "{elapsed} ! separator not at end of string";
+ nok $elapsed > $toolong, "took too long 14";
+ is $expected[$i++], ' Callooh',
+ "{elapsed} Multiple separators not at end of string";
+ nok $elapsed > $toolong, "took too long 15";
+ is $expected[$i++], ' Callay',
+ "{elapsed} ! separator at end of string";
# RT #116288, test 6 tests read with a parameter
if $is-win {
@@ -132,8 +154,11 @@ if $*OS eq any <linux darwin solaris MSWin32> { # please add more valid OS names
$expected = $received.split("\n");
$i = 0;
is $expected[$i++], '0', "{elapsed} received first character";
+ nok $elapsed > $toolong, "took too long 16";
is $expected[$i++], '3', "{elapsed} received last character";
+ nok $elapsed > $toolong, "took too long 17";
is $expected[$i++], 4096 * 4, "{elapsed} total amount ";
+ nok $elapsed > $toolong, "took too long 18";
# test 7 tests recv with binary data
if $is-win {
@@ -143,6 +168,7 @@ if $*OS eq any <linux darwin solaris MSWin32> { # please add more valid OS names
}
$expected = $received.split("\n");
is $expected[0], 'OK-7', "{elapsed} successful read binary data";
+ nok $elapsed > $toolong, "took too long 19";
# test 8 tests recv with binary data.
if $is-win {
@@ -152,6 +178,7 @@ if $*OS eq any <linux darwin solaris MSWin32> { # please add more valid OS names
}
$expected = $received.split("\n");
is $expected[0], 'OK-8', "{elapsed} successful received binary data";
+ nok $elapsed > $toolong, "took too long 20";
}
else {
skip "OS '$*OS' shell support not confirmed", 1;

0 comments on commit ef215fd

Please sign in to comment.