Code Duplication    Length = 41-41 lines in 2 locations

tests/ProcessRegistryTest.php 2 locations

@@ 217-257 (lines=41) @@
214
     *
215
     * @return void
216
     */
217
    public function addCleaningNotRunningProcessWithExtra()
218
    {
219
        $pipes = [];
220
        $process = proc_open('sleep 3 &', self::getDevNullProcOpenDescriptors(), $pipes);
221
        $status = proc_get_status($process);
222
        if (!$status['running']) {
223
            $this->markTestSkipped('Unable to start sleep process.');
224
            return;
225
        }
226
227
        $extraPid = $status['pid'];
228
229
        $expireSecs = time() + 60;
230
        $initialVersion = new ObjectID();
231
        $initalTask = [
232
            '_id' => 'testId',
233
            'hosts' => [
234
                HOSTNAME => [
235
                    $extraPid => $expireSecs,
236
                    '9999999' => $expireSecs,
237
                ],
238
            ],
239
            'version' => $initialVersion,
240
        ];
241
242
        $this->collection->insertOne($initalTask);
243
244
        $this->assertTrue($this->registry->add($this->getProcess('testId', PHP_INT_MAX, 2, 2)));
245
246
        $this->assertSame(1, $this->collection->count());
247
        $result = $this->collection->findOne();
248
249
        $expected = [
250
            '_id' => 'testId',
251
            'hosts' => [HOSTNAME => [$extraPid => $expireSecs, getmypid() => ProcessRegistry::MONGO_INT32_MAX]],
252
            'version' => $result['version'],
253
        ];
254
255
        $this->assertSame($expected, $result);
256
        $this->assertNotSame((string)$initialVersion, (string)$result['version']);
257
    }
258
259
    /**
260
     * @test
@@ 370-410 (lines=41) @@
367
     *
368
     * @return void
369
     */
370
    public function addCleaningRecycledProcessWithExtra()
371
    {
372
        $pipes = [];
373
        $process = proc_open('sleep 3 &', self::getDevNullProcOpenDescriptors(), $pipes);
374
        $status = proc_get_status($process);
375
        if (!$status['running']) {
376
            $this->markTestSkipped('Unable to start sleep process.');
377
            return;
378
        }
379
380
        $extraPid = $status['pid'];
381
382
        $expireSecs = time() + 60;
383
        $initialVersion = new ObjectID();
384
        $initalTask = [
385
            '_id' => 'testId',
386
            'hosts' => [
387
                HOSTNAME => [
388
                    $extraPid => $expireSecs,
389
                    getmypid() => $expireSecs,
390
                ],
391
            ],
392
            'version' => $initialVersion,
393
        ];
394
395
        $this->collection->insertOne($initalTask);
396
397
        $this->assertTrue($this->registry->add($this->getProcess('testId', PHP_INT_MAX, 2, 2)));
398
399
        $this->assertSame(1, $this->collection->count());
400
        $result = $this->collection->findOne();
401
402
        $expected = [
403
            '_id' => 'testId',
404
            'hosts' => [HOSTNAME => [$extraPid => $expireSecs, getmypid() => ProcessRegistry::MONGO_INT32_MAX]],
405
            'version' => $result['version'],
406
        ];
407
408
        $this->assertSame($expected, $result);
409
        $this->assertNotSame((string)$initialVersion, (string)$result['version']);
410
    }
411
412
    /**
413
     * @test