File tree 2 files changed +17
-8
lines changed
src/Symfony/Component/Process
2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -450,27 +450,28 @@ public function waitUntil(callable $callback): bool
450
450
}
451
451
$ callback = $ this ->buildCallback ($ callback );
452
452
453
- $ wait = true ;
454
- do {
453
+ $ ready = false ;
454
+ while ( true ) {
455
455
$ this ->checkTimeout ();
456
456
$ running = '\\' === \DIRECTORY_SEPARATOR ? $ this ->isRunning () : $ this ->processPipes ->areOpen ();
457
457
$ output = $ this ->processPipes ->readAndWrite ($ running , '\\' !== \DIRECTORY_SEPARATOR || !$ running );
458
458
459
459
foreach ($ output as $ type => $ data ) {
460
460
if (3 !== $ type ) {
461
- $ wait = ! $ callback (self ::STDOUT === $ type ? self ::OUT : self ::ERR , $ data );
461
+ $ ready = $ ready || $ callback (self ::STDOUT === $ type ? self ::OUT : self ::ERR , $ data );
462
462
} elseif (!isset ($ this ->fallbackStatus ['signaled ' ])) {
463
463
$ this ->fallbackStatus ['exitcode ' ] = (int ) $ data ;
464
464
}
465
465
}
466
- if ($ wait && !$ this ->isRunning ()) {
466
+ if ($ ready ) {
467
+ return true ;
468
+ }
469
+ if (!$ running ) {
467
470
return false ;
468
471
}
469
472
470
473
usleep (1000 );
471
- } while ($ wait );
472
-
473
- return true ;
474
+ }
474
475
}
475
476
476
477
/**
Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ public function testWaitUntilSpecificOutput()
141
141
$ start = microtime (true );
142
142
143
143
$ completeOutput = '' ;
144
- $ p ->waitUntil (function ($ type , $ output ) use (&$ completeOutput ) {
144
+ $ result = $ p ->waitUntil (function ($ type , $ output ) use (&$ completeOutput ) {
145
145
$ completeOutput .= $ output ;
146
146
if (false !== strpos ($ output , 'One more ' )) {
147
147
return true ;
@@ -150,6 +150,7 @@ public function testWaitUntilSpecificOutput()
150
150
return false ;
151
151
});
152
152
$ p ->stop ();
153
+ $ this ->assertTrue ($ result );
153
154
154
155
if ('\\' === \DIRECTORY_SEPARATOR ) {
155
156
// Windows is slower
@@ -160,6 +161,13 @@ public function testWaitUntilSpecificOutput()
160
161
$ this ->assertEquals ("First iteration output \nSecond iteration output \nOne more iteration output \n" , $ completeOutput );
161
162
}
162
163
164
+ public function testWaitUntilCanReturnFalse ()
165
+ {
166
+ $ p = $ this ->getProcess ('echo foo ' );
167
+ $ p ->start ();
168
+ $ this ->assertFalse ($ p ->waitUntil (function () { return false ; }));
169
+ }
170
+
163
171
public function testAllOutputIsActuallyReadOnTermination ()
164
172
{
165
173
// this code will result in a maximum of 2 reads of 8192 bytes by calling
You can’t perform that action at this time.
0 commit comments