| @@ 76-104 (lines=29) @@ | ||
| 73 | * |
|
| 74 | * @return void |
|
| 75 | */ |
|
| 76 | public function addExistingDifferentHost() |
|
| 77 | { |
|
| 78 | $expireSecs = time() + 60; |
|
| 79 | $initialVersion = new ObjectID(); |
|
| 80 | $initalTask = [ |
|
| 81 | '_id' => 'testId', |
|
| 82 | 'hosts' => ['a host' => ['1' => $expireSecs]], |
|
| 83 | 'version' => $initialVersion, |
|
| 84 | ]; |
|
| 85 | ||
| 86 | $this->collection->insertOne($initalTask); |
|
| 87 | ||
| 88 | $this->assertTrue($this->registry->add($this->getProcess('testId', PHP_INT_MAX, 2, 1))); |
|
| 89 | ||
| 90 | $this->assertSame(1, $this->collection->count()); |
|
| 91 | $result = $this->collection->findOne(); |
|
| 92 | ||
| 93 | $expected = [ |
|
| 94 | '_id' => 'testId', |
|
| 95 | 'hosts' => [ |
|
| 96 | 'a host' => ['1' => $expireSecs], |
|
| 97 | HOSTNAME => [getmypid() => ProcessRegistry::MONGO_INT32_MAX], |
|
| 98 | ], |
|
| 99 | 'version' => $result['version'], |
|
| 100 | ]; |
|
| 101 | ||
| 102 | $this->assertSame($expected, $result); |
|
| 103 | $this->assertNotSame((string)$initialVersion, (string)$result['version']); |
|
| 104 | } |
|
| 105 | ||
| 106 | /** |
|
| 107 | * @test |
|
| @@ 297-330 (lines=34) @@ | ||
| 294 | * |
|
| 295 | * @return void |
|
| 296 | */ |
|
| 297 | public function addCleaningExpiredProcessWithExtra() |
|
| 298 | { |
|
| 299 | $expireSecs = time() + 60; |
|
| 300 | $initialVersion = new ObjectID(); |
|
| 301 | $initalTask = [ |
|
| 302 | '_id' => 'testId', |
|
| 303 | 'hosts' => [ |
|
| 304 | 'a host' => [ |
|
| 305 | '2' => time() - 1, |
|
| 306 | '1' => $expireSecs, |
|
| 307 | ], |
|
| 308 | ], |
|
| 309 | 'version' => $initialVersion, |
|
| 310 | ]; |
|
| 311 | ||
| 312 | $this->collection->insertOne($initalTask); |
|
| 313 | ||
| 314 | $this->assertTrue($this->registry->add($this->getProcess('testId', PHP_INT_MAX, 2, 2))); |
|
| 315 | ||
| 316 | $this->assertSame(1, $this->collection->count()); |
|
| 317 | $result = $this->collection->findOne(); |
|
| 318 | ||
| 319 | $expected = [ |
|
| 320 | '_id' => 'testId', |
|
| 321 | 'hosts' => [ |
|
| 322 | 'a host' => ['1' => $expireSecs], |
|
| 323 | HOSTNAME => [getmypid() => ProcessRegistry::MONGO_INT32_MAX] |
|
| 324 | ], |
|
| 325 | 'version' => $result['version'], |
|
| 326 | ]; |
|
| 327 | ||
| 328 | $this->assertSame($expected, $result); |
|
| 329 | $this->assertNotSame((string)$initialVersion, (string)$result['version']); |
|
| 330 | } |
|
| 331 | ||
| 332 | /** |
|
| 333 | * @test |
|