Skip to content

Commit 8624a44

Browse files
committed
Fix more instances where t/01_run.t might fail
This will hopefully fix test failures like: ``` [ 420s] # Failed test 'Process now is not running' [ 420s] # at t/01_run.t line 110. [ 420s] # got: '1' [ 420s] # expected: '0' [ 421s] # Looks like you failed 1 test of 7. [ 421s] [ 421s] # Failed test 'process is_running()' [ 421s] # at t/01_run.t line 129. [ 427s] TEST error print ``` Related ticket: https://progress.opensuse.org/issues/178183
1 parent 4b253c8 commit 8624a44

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

t/01_run.t

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ use lib ("$FindBin::Bin/lib", "../lib", "lib");
1212
use Mojo::IOLoop::ReadWriteProcess qw(process);
1313
use Mojo::IOLoop::ReadWriteProcess::Test::Utils qw(attempt check_bin);
1414

15+
my $interval = $ENV{MOJO_PROCESS_TEST_SLEEP_INTERVAL} // 0.01;
16+
my $timeout = $ENV{MOJO_PROCESS_SUBTEST_TIMEOUT} // 15;
17+
my $kill_sleeptime = $ENV{TOTAL_SLEEPTIME_DURING_KILL} // ($interval * 5.0);
18+
1519
subtest process => sub {
1620

1721
my $c = Mojo::IOLoop::ReadWriteProcess->new();
@@ -68,13 +72,13 @@ subtest 'process basic functions' => sub {
6872
};
6973

7074
subtest 'process is_running()' => sub {
71-
7275
my @output;
7376
pipe(PARENT, CHILD);
7477

75-
my $p = Mojo::IOLoop::ReadWriteProcess->new(
76-
kill_sleeptime => 0.01,
77-
sleeptime_during_kill => 0.01,
78+
my $patience = $timeout / $interval;
79+
my $p = Mojo::IOLoop::ReadWriteProcess->new(
80+
kill_sleeptime => $interval,
81+
sleeptime_during_kill => $interval,
7882
code => sub {
7983
close(PARENT);
8084
open STDERR, ">&", \*CHILD or die $!;
@@ -85,6 +89,7 @@ subtest 'process is_running()' => sub {
8589
close(CHILD);
8690
@output = scalar <PARENT>;
8791
$p->stop();
92+
sleep $interval while $p->is_running && --$patience > 0;
8893

8994
close(PARENT);
9095
chomp @output;
@@ -101,10 +106,12 @@ subtest 'process is_running()' => sub {
101106
1 while 1;
102107
});
103108
$p->restart()->restart()->restart();
109+
sleep $interval until $p->is_running || --$patience <= 0;
104110
is $p->is_running, 1, "Process now is running";
105111
close(CHILD);
106112
@output = scalar <PARENT>;
107113
$p->stop();
114+
sleep $interval while $p->is_running && --$patience > 0;
108115
chomp @output;
109116
is $output[0], "FOOBAZFTW", 'right output from process';
110117
is $p->is_running, 0, "Process now is not running";
@@ -113,13 +120,7 @@ subtest 'process is_running()' => sub {
113120
pipe(PARENT, CHILD);
114121
$p->restart();
115122

116-
# Give time to the child to be up
117-
my $attempts = 100;
118-
until ($p->is_running || $attempts == 0) {
119-
sleep .1;
120-
$attempts--;
121-
}
122-
123+
sleep $interval until $p->is_running || --$patience <= 0;
123124
is $p->is_running, 1, "Process now is running";
124125
close(CHILD);
125126
@output = scalar <PARENT>;
@@ -178,13 +179,15 @@ subtest 'process execute()' => sub {
178179
is $p->getline, "FOO BAZ\n", 'process received extra arguments';
179180
is $p->exit_status, 100, 'able to retrieve function return';
180181

182+
my $patience = $timeout / $interval;
181183
$p = Mojo::IOLoop::ReadWriteProcess->new(
182184
kill_sleeptime => 0.01,
183185
sleeptime_during_kill => 0.01,
184186
separate_err => 0,
185187
execute => $test_script
186188
);
187189
$p->start();
190+
sleep $interval until $p->is_running || --$patience <= 0;
188191
is $p->is_running, 1, 'process is still running';
189192
is $p->getline, "TEST error print\n",
190193
'Get STDERR output from stdout, always in getline()';
@@ -338,7 +341,7 @@ subtest 'process code()' => sub {
338341
is $p->channel_out->getline, "FOOBARftw\n", "can read from internal channel";
339342
is $p->channel_read_handle->getline, "PONG\n",
340343
"can read from internal channel";
341-
$p->stop();
344+
$p->stop->wait;
342345
is $p->is_running, 0, 'process is not running';
343346
$p->restart();
344347

@@ -354,7 +357,7 @@ subtest 'process code()' => sub {
354357

355358
is $p->read_all, "Enter something : you entered FOOBAR\n",
356359
'Get right output from stdout';
357-
$p->stop();
360+
$p->stop->wait;
358361

359362
my @result = $p->read_all;
360363
is @result, 0, 'output buffer is now empty';
@@ -482,11 +485,8 @@ subtest stop_whole_process_group_gracefully => sub {
482485
# to check whether the sub processes would actually be granted
483486
# this number of seconds before getting killed. This is not set by
484487
# default to avoid slowing down the CI.
485-
my $interval = $ENV{MOJO_PROCESS_STOP_PGROUP_SLEEP_INTERVAL} // 0.01;
486-
my $timeout = $ENV{MOJO_PROCESS_STOP_PGROUP_TIMEOUT} // 15;
487-
my $kill_sleeptime = $ENV{TOTAL_SLEEPTIME_DURING_KILL} // ($interval * 5.0);
488-
my $patience = $timeout / $interval;
489-
my $sub_process = Mojo::IOLoop::ReadWriteProcess->new(
488+
my $patience = $timeout / $interval;
489+
my $sub_process = Mojo::IOLoop::ReadWriteProcess->new(
490490
kill_sleeptime => $interval,
491491
sleeptime_during_kill => $interval,
492492
max_kill_attempts => 1,

0 commit comments

Comments
 (0)