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