Skip to content

Commit 6e9fe37

Browse files
committed
Remove unneeded start timers from tests
1 parent 662d4db commit 6e9fe37

1 file changed

Lines changed: 33 additions & 47 deletions

File tree

tests/AbstractProcessTest.php

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,13 @@ public function testProcessWithDefaultCwdAndEnv()
151151
$cmd = $this->getPhpBinary() . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL, count($_SERVER), PHP_EOL;');
152152

153153
$loop = $this->createLoop();
154+
154155
$process = new Process($cmd);
156+
$process->start($loop);
155157

156158
$output = '';
157-
158-
$loop->addTimer(0.001, function () use ($process, $loop, &$output) {
159-
$process->start($loop);
160-
$process->stdout->on('data', function () use (&$output) {
161-
$output .= func_get_arg(0);
162-
});
159+
$process->stdout->on('data', function () use (&$output) {
160+
$output .= func_get_arg(0);
163161
});
164162

165163
$loop->run();
@@ -179,15 +177,13 @@ public function testProcessWithCwd()
179177
$cmd = $this->getPhpBinary() . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL;');
180178

181179
$loop = $this->createLoop();
180+
182181
$process = new Process($cmd, '/');
182+
$process->start($loop);
183183

184184
$output = '';
185-
186-
$loop->addTimer(0.001, function () use ($process, $loop, &$output) {
187-
$process->start($loop);
188-
$process->stdout->on('data', function () use (&$output) {
189-
$output .= func_get_arg(0);
190-
});
185+
$process->stdout->on('data', function () use (&$output) {
186+
$output .= func_get_arg(0);
191187
});
192188

193189
$loop->run();
@@ -204,15 +200,13 @@ public function testProcessWithEnv()
204200
$cmd = $this->getPhpBinary() . ' -r ' . escapeshellarg('echo getenv("foo"), PHP_EOL;');
205201

206202
$loop = $this->createLoop();
203+
207204
$process = new Process($cmd, null, array('foo' => 'bar'));
205+
$process->start($loop);
208206

209207
$output = '';
210-
211-
$loop->addTimer(0.001, function () use ($process, $loop, &$output) {
212-
$process->start($loop);
213-
$process->stdout->on('data', function () use (&$output) {
214-
$output .= func_get_arg(0);
215-
});
208+
$process->stdout->on('data', function () use (&$output) {
209+
$output .= func_get_arg(0);
216210
});
217211

218212
$loop->run();
@@ -235,9 +229,7 @@ public function testStartAndAllowProcessToExitSuccessfullyUsingEventLoop()
235229
$termSignal = func_get_arg(1);
236230
});
237231

238-
$loop->addTimer(0.001, function () use ($process, $loop) {
239-
$process->start($loop);
240-
});
232+
$process->start($loop);
241233

242234
$loop->run();
243235

@@ -256,15 +248,13 @@ public function testStartInvalidProcess()
256248
$cmd = tempnam(sys_get_temp_dir(), 'react');
257249

258250
$loop = $this->createLoop();
251+
259252
$process = new Process($cmd);
253+
$process->start($loop);
260254

261255
$output = '';
262-
263-
$loop->addTimer(0.001, function () use ($process, $loop, &$output) {
264-
$process->start($loop);
265-
$process->stderr->on('data', function () use (&$output) {
266-
$output .= func_get_arg(0);
267-
});
256+
$process->stderr->on('data', function () use (&$output) {
257+
$output .= func_get_arg(0);
268258
});
269259

270260
$loop->run();
@@ -337,10 +327,8 @@ public function testTerminateWithDefaultTermSignalUsingEventLoop()
337327
$termSignal = func_get_arg(1);
338328
});
339329

340-
$loop->addTimer(0.001, function () use ($process, $loop) {
341-
$process->start($loop);
342-
$process->terminate();
343-
});
330+
$process->start($loop);
331+
$process->terminate();
344332

345333
$loop->run();
346334

@@ -378,22 +366,20 @@ public function testTerminateWithStopAndContinueSignalsUsingEventLoop()
378366
});
379367

380368
$that = $this;
381-
$loop->addTimer(0.001, function () use ($process, $loop, $that) {
382-
$process->start($loop);
383-
$process->terminate(SIGSTOP);
384-
385-
$that->assertSoon(function () use ($process, $that) {
386-
$that->assertTrue($process->isStopped());
387-
$that->assertTrue($process->isRunning());
388-
$that->assertEquals(SIGSTOP, $process->getStopSignal());
389-
});
390-
391-
$process->terminate(SIGCONT);
392-
393-
$that->assertSoon(function () use ($process, $that) {
394-
$that->assertFalse($process->isStopped());
395-
$that->assertEquals(SIGSTOP, $process->getStopSignal());
396-
});
369+
$process->start($loop);
370+
$process->terminate(SIGSTOP);
371+
372+
$that->assertSoon(function () use ($process, $that) {
373+
$that->assertTrue($process->isStopped());
374+
$that->assertTrue($process->isRunning());
375+
$that->assertEquals(SIGSTOP, $process->getStopSignal());
376+
});
377+
378+
$process->terminate(SIGCONT);
379+
380+
$that->assertSoon(function () use ($process, $that) {
381+
$that->assertFalse($process->isStopped());
382+
$that->assertEquals(SIGSTOP, $process->getStopSignal());
397383
});
398384

399385
$loop->run();

0 commit comments

Comments
 (0)