From e9a81b456202679d408f13910c9a2a0ff5eac973 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 14 Apr 2011 04:01:07 -0500 Subject: make the tests a bit more reliable there are probably still race conditions here (this is pretty hacky in general), but it's miles better than "sleep", so we'll go with it for now. --- t/03-write-to-termcast.t | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 't/03-write-to-termcast.t') diff --git a/t/03-write-to-termcast.t b/t/03-write-to-termcast.t index f8f1950..5b7c4b2 100644 --- a/t/03-write-to-termcast.t +++ b/t/03-write-to-termcast.t @@ -6,33 +6,45 @@ use Test::Requires 'Test::TCP'; use App::Termcast; +pipe(my $cread, my $swrite); +pipe(my $sread, my $cwrite); + test_tcp( client => sub { my $port = shift; + close $swrite; + close $sread; + { sysread($cread, my $buf, 1) } my $tc = App::Termcast->new( host => '127.0.0.1', port => $port, user => 'test', password => 'tset'); $tc->write_to_termcast('foo'); + syswrite($cwrite, 'a'); + { sysread($cread, my $buf, 1) } ok(!$tc->meta->find_attribute_by_name('pty')->has_value($tc), "pty isn't created"); - sleep 1; }, server => sub { my $port = shift; + close $cwrite; + close $cread; my $sock = IO::Socket::INET->new(LocalAddr => '127.0.0.1', LocalPort => $port, Listen => 1); $sock->accept; # signal to the client that the port is available + syswrite($swrite, 'a'); my $client = $sock->accept; my $login; $client->recv($login, 4096); my $auth_regexp = qr/^hello test tset\n(?:\e\[H\x00.+?\xff\e\[H\e\[2J)?/; like($login, $auth_regexp, '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'); + syswrite($swrite, 'a'); }, ); -- cgit v1.2.3-54-g00ecf