Mercurial > hg > nginx-tests
comparison lib/Test/Nginx.pm @ 50:b494fe5b12d1
Tests: add waitforfile() and waitforsocket() functions.
This functions add ability to wait for external daemons to start before running
tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 19 Nov 2008 17:31:03 +0300 |
parents | b01ae969181b |
children | d59ae7bab0a6 |
comparison
equal
deleted
inserted
replaced
49:b01ae969181b | 50:b494fe5b12d1 |
---|---|
96 or die "Unable to exec(): $!\n"; | 96 or die "Unable to exec(): $!\n"; |
97 } | 97 } |
98 | 98 |
99 # wait for nginx to start | 99 # wait for nginx to start |
100 | 100 |
101 $self->waitforfile("$testdir/nginx.pid") | |
102 or die "Can't start nginx"; | |
103 | |
104 $self->{_started} = 1; | |
105 return $self; | |
106 } | |
107 | |
108 sub waitforfile($) { | |
109 my ($self, $file) = @_; | |
110 | |
111 # wait for file to appear | |
112 | |
101 for (1 .. 30) { | 113 for (1 .. 30) { |
102 select undef, undef, undef, 0.05; | 114 return 1 if -e $file; |
103 last if -e "$self->{_testdir}/nginx.pid"; | 115 select undef, undef, undef, 0.1; |
104 } | 116 } |
105 | 117 |
106 die "Can't start nginx" unless -e "$self->{_testdir}/nginx.pid"; | 118 return undef; |
107 | 119 } |
108 $self->{_started} = 1; | 120 |
109 return $self; | 121 sub waitforsocket($) { |
122 my ($self, $peer) = @_; | |
123 | |
124 # wait for socket to accept connections | |
125 | |
126 for (1 .. 30) { | |
127 my $s = IO::Socket::INET->new( | |
128 Proto => 'tcp', | |
129 PeerAddr => $peer | |
130 ); | |
131 | |
132 return 1 if defined $s; | |
133 | |
134 select undef, undef, undef, 0.1; | |
135 } | |
136 | |
137 return undef; | |
110 } | 138 } |
111 | 139 |
112 sub stop() { | 140 sub stop() { |
113 my ($self) = @_; | 141 my ($self) = @_; |
114 | 142 |