summaryrefslogtreecommitdiffstats
path: root/t/write-to-termcast.t
diff options
context:
space:
mode:
Diffstat (limited to 't/write-to-termcast.t')
-rw-r--r--t/write-to-termcast.t38
1 files changed, 30 insertions, 8 deletions
diff --git a/t/write-to-termcast.t b/t/write-to-termcast.t
index 8a5ed1b..2be2c36 100644
--- a/t/write-to-termcast.t
+++ b/t/write-to-termcast.t
@@ -13,6 +13,8 @@ use warnings 'redefine';
pipe(my $cread, my $swrite);
pipe(my $sread, my $cwrite);
+alarm 60;
+
test_tcp(
client => sub {
my $port = shift;
@@ -20,8 +22,11 @@ test_tcp(
close $sread;
{ sysread($cread, my $buf, 1) }
my $tc = App::Termcast->new(
- host => '127.0.0.1', port => $port,
- user => 'test', password => 'tset');
+ host => '127.0.0.1',
+ port => $port,
+ user => 'test',
+ password => 'tset',
+ );
$tc->write_to_termcast('foo');
syswrite($cwrite, 'a');
{ sysread($cread, my $buf, 1) }
@@ -38,19 +43,36 @@ test_tcp(
$sock->accept; # signal to the client that the port is available
syswrite($swrite, 'a');
my $client = $sock->accept;
- my $login;
- $client->recv($login, 4096);
- is($login,
+ is(full_read($client),
"hello test tset\n\e\[H\x00{\"geometry\":[80,24]}\xff\e\[H\e\[2J",
"got the correct login info");
$client->send("hello, test\n");
{ sysread($sread, my $buf, 1) }
- my $buf;
- $client->recv($buf, 4096);
- is($buf, 'foo', 'wrote correctly');
+ is(full_read($client), "foo");
syswrite($swrite, 'a');
+ sleep 1 while $client->connected;
},
);
+sub full_read {
+ my ($fh) = @_;
+
+ my $select = IO::Select->new($fh);
+ return if $select->has_exception(0.1);
+
+ 1 while !$select->can_read(1);
+
+ my $ret;
+ while ($select->can_read(1)) {
+ my $new;
+ sysread($fh, $new, 4096);
+ last unless defined($new) && length($new);
+ $ret .= $new;
+ return $ret if $select->has_exception(0.1);
+ }
+
+ return $ret;
+}
+
done_testing;