@@ -828,30 +828,29 @@ public function testCheckTimeoutOnStartedProcess()
828
828
$ process ->checkTimeout ();
829
829
usleep (100000 );
830
830
}
831
- $ this ->fail ('A RuntimeException should have been raised ' );
832
- } catch (RuntimeException $ e ) {
831
+ $ this ->fail ('A ProcessTimedOutException should have been raised ' );
832
+ } catch (ProcessTimedOutException $ e ) {
833
833
}
834
- $ duration = microtime (true ) - $ start ;
835
834
836
- $ this ->assertLessThan (3 , $ duration );
835
+ $ this ->assertLessThan (15 , microtime ( true ) - $ start );
837
836
838
837
throw $ e ;
839
838
}
840
839
841
840
public function testIdleTimeout ()
842
841
{
843
- $ process = $ this ->getProcess (self ::$ phpBin .' -r "sleep(3 );" ' );
844
- $ process ->setTimeout (10 );
845
- $ process ->setIdleTimeout (0.5 );
842
+ $ process = $ this ->getProcess (self ::$ phpBin .' -r "sleep(34 );" ' );
843
+ $ process ->setTimeout (60 );
844
+ $ process ->setIdleTimeout (0.1 );
846
845
847
846
try {
848
847
$ process ->run ();
849
848
850
849
$ this ->fail ('A timeout exception was expected. ' );
851
- } catch (ProcessTimedOutException $ ex ) {
852
- $ this ->assertTrue ($ ex ->isIdleTimeout ());
853
- $ this ->assertFalse ($ ex ->isGeneralTimeout ());
854
- $ this ->assertEquals (0.5 , $ ex ->getExceededTimeout ());
850
+ } catch (ProcessTimedOutException $ e ) {
851
+ $ this ->assertTrue ($ e ->isIdleTimeout ());
852
+ $ this ->assertFalse ($ e ->isGeneralTimeout ());
853
+ $ this ->assertEquals (0.1 , $ e ->getExceededTimeout ());
855
854
}
856
855
}
857
856
@@ -860,17 +859,23 @@ public function testIdleTimeoutNotExceededWhenOutputIsSent()
860
859
if ('\\' === DIRECTORY_SEPARATOR ) {
861
860
$ this ->markTestIncomplete ('This test fails with a timeout on Windows, can someone investigate please? ' );
862
861
}
863
- $ process = $ this ->getProcess (sprintf ('%s -r %s ' , self ::$ phpBin , escapeshellarg ('$n = 30; while ($n--) {echo "foo\n"; usleep(100000); } ' )));
864
- $ process ->setTimeout (2 );
865
- $ process ->setIdleTimeout (1 );
862
+ $ process = $ this ->getProcess (sprintf ('%s -r %s ' , self ::$ phpBin , escapeshellarg ('while (true) {echo "foo\n"; usleep(10000);} ' )));
863
+ $ process ->setTimeout (1 );
864
+ $ process ->start ();
865
+
866
+ while (false === strpos ($ process ->getOutput (), 'foo ' )) {
867
+ usleep (1000 );
868
+ }
869
+
870
+ $ process ->setIdleTimeout (0.1 );
866
871
867
872
try {
868
- $ process ->run ();
873
+ $ process ->wait ();
869
874
$ this ->fail ('A timeout exception was expected. ' );
870
875
} catch (ProcessTimedOutException $ ex ) {
871
876
$ this ->assertTrue ($ ex ->isGeneralTimeout (), 'A general timeout is expected. ' );
872
877
$ this ->assertFalse ($ ex ->isIdleTimeout (), 'No idle timeout is expected. ' );
873
- $ this ->assertEquals (2 , $ ex ->getExceededTimeout ());
878
+ $ this ->assertEquals (1 , $ ex ->getExceededTimeout ());
874
879
}
875
880
}
876
881
@@ -885,11 +890,12 @@ public function testStartAfterATimeout()
885
890
886
891
try {
887
892
$ process ->run ();
888
- $ this ->fail ('A RuntimeException should have been raised. ' );
889
- } catch (RuntimeException $ e ) {
893
+ $ this ->fail ('A ProcessTimedOutException should have been raised. ' );
894
+ } catch (ProcessTimedOutException $ e ) {
890
895
}
891
896
$ this ->assertFalse ($ process ->isRunning ());
892
897
$ process ->start ();
898
+ $ this ->assertTrue ($ process ->isRunning ());
893
899
$ process ->stop (0 );
894
900
895
901
throw $ e ;
@@ -1047,7 +1053,7 @@ public function provideWrongSignal()
1047
1053
1048
1054
public function testDisableOutputDisablesTheOutput ()
1049
1055
{
1050
- $ p = $ this ->getProcess (self :: $ phpBin . ' -r "usleep(500000);" ' );
1056
+ $ p = $ this ->getProcess (' foo ' );
1051
1057
$ this ->assertFalse ($ p ->isOutputDisabled ());
1052
1058
$ p ->disableOutput ();
1053
1059
$ this ->assertTrue ($ p ->isOutputDisabled ());
@@ -1061,7 +1067,7 @@ public function testDisableOutputDisablesTheOutput()
1061
1067
*/
1062
1068
public function testDisableOutputWhileRunningThrowsException ()
1063
1069
{
1064
- $ p = $ this ->getProcess (self ::$ phpBin .' -r "usleep(500000 );" ' );
1070
+ $ p = $ this ->getProcess (self ::$ phpBin .' -r "sleep(39 );" ' );
1065
1071
$ p ->start ();
1066
1072
$ p ->disableOutput ();
1067
1073
}
@@ -1072,20 +1078,20 @@ public function testDisableOutputWhileRunningThrowsException()
1072
1078
*/
1073
1079
public function testEnableOutputWhileRunningThrowsException ()
1074
1080
{
1075
- $ p = $ this ->getProcess (self ::$ phpBin .' -r "usleep(500000 );" ' );
1081
+ $ p = $ this ->getProcess (self ::$ phpBin .' -r "sleep(40 );" ' );
1076
1082
$ p ->disableOutput ();
1077
1083
$ p ->start ();
1078
1084
$ p ->enableOutput ();
1079
1085
}
1080
1086
1081
1087
public function testEnableOrDisableOutputAfterRunDoesNotThrowException ()
1082
1088
{
1083
- $ p = $ this ->getProcess (self :: $ phpBin . ' -r "usleep(500000);" ' );
1089
+ $ p = $ this ->getProcess (' echo foo ' );
1084
1090
$ p ->disableOutput ();
1085
- $ p ->start ();
1086
- $ p ->wait ();
1091
+ $ p ->run ();
1087
1092
$ p ->enableOutput ();
1088
1093
$ p ->disableOutput ();
1094
+ $ this ->assertTrue ($ p ->isOutputDisabled ());
1089
1095
}
1090
1096
1091
1097
/**
@@ -1094,7 +1100,7 @@ public function testEnableOrDisableOutputAfterRunDoesNotThrowException()
1094
1100
*/
1095
1101
public function testDisableOutputWhileIdleTimeoutIsSet ()
1096
1102
{
1097
- $ process = $ this ->getProcess ('sleep 3 ' );
1103
+ $ process = $ this ->getProcess ('foo ' );
1098
1104
$ process ->setIdleTimeout (1 );
1099
1105
$ process ->disableOutput ();
1100
1106
}
@@ -1105,24 +1111,24 @@ public function testDisableOutputWhileIdleTimeoutIsSet()
1105
1111
*/
1106
1112
public function testSetIdleTimeoutWhileOutputIsDisabled ()
1107
1113
{
1108
- $ process = $ this ->getProcess ('sleep 3 ' );
1114
+ $ process = $ this ->getProcess ('foo ' );
1109
1115
$ process ->disableOutput ();
1110
1116
$ process ->setIdleTimeout (1 );
1111
1117
}
1112
1118
1113
1119
public function testSetNullIdleTimeoutWhileOutputIsDisabled ()
1114
1120
{
1115
- $ process = $ this ->getProcess ('sleep 3 ' );
1121
+ $ process = $ this ->getProcess ('foo ' );
1116
1122
$ process ->disableOutput ();
1117
- $ process ->setIdleTimeout (null );
1123
+ $ this -> assertSame ( $ process, $ process ->setIdleTimeout (null ) );
1118
1124
}
1119
1125
1120
1126
/**
1121
1127
* @dataProvider provideStartMethods
1122
1128
*/
1123
1129
public function testStartWithACallbackAndDisabledOutput ($ startMethod , $ exception , $ exceptionMessage )
1124
1130
{
1125
- $ p = $ this ->getProcess (self :: $ phpBin . ' -r "usleep(500000);" ' );
1131
+ $ p = $ this ->getProcess (' foo ' );
1126
1132
$ p ->disableOutput ();
1127
1133
$ this ->setExpectedException ($ exception , $ exceptionMessage );
1128
1134
if ('mustRun ' === $ startMethod ) {
@@ -1147,7 +1153,7 @@ public function provideStartMethods()
1147
1153
*/
1148
1154
public function testGetOutputWhileDisabled ($ fetchMethod )
1149
1155
{
1150
- $ p = $ this ->getProcess (self ::$ phpBin .' -r "usleep(500000 );" ' );
1156
+ $ p = $ this ->getProcess (self ::$ phpBin .' -r "sleep(41 );" ' );
1151
1157
$ p ->disableOutput ();
1152
1158
$ p ->start ();
1153
1159
$ p ->{$ fetchMethod }();
@@ -1162,7 +1168,7 @@ public function provideOutputFetchingMethods()
1162
1168
array ('getIncrementalErrorOutput ' ),
1163
1169
);
1164
1170
}
1165
-
1171
+
1166
1172
public function testStopTerminatesProcessCleanly ()
1167
1173
{
1168
1174
$ process = $ this ->getProcess (self ::$ phpBin .' -r "echo 123; sleep(42);" ' );
0 commit comments