public function testPingWorkers() { try { $wp = new WorkerPool(); $wp->setWorkerPoolSize(50); $wp->create(new Fixtures\PingWorker()); $failCount = 0; for ($i = 0; $i < 500; $i++) { $wp->run($i); $a = $wp->getFreeAndBusyWorkers(); if ($a['free'] + $a['busy'] != $a['total']) { $failCount++; } } $wp->waitForAllWorkers(); $this->assertLessThanOrEqual(0, $failCount, 'Sometimes the sum of free and busy workers does not equal to the pool size.'); $this->assertEquals(500, count($wp), 'The result count should be 500.'); $i = 0; foreach ($wp as $val) { $i++; } $this->assertEquals(500, $i, 'We should have 500 results in the pool.'); $this->assertEquals(0, count($wp), 'The result count should be 0 now.'); } catch (\Exception $e) { $this->assertTrue(FALSE, 'An unexpected exception was thrown.'); } try { $wp->destroy(); } catch (\Exception $e) { $this->assertTrue(FALSE, 'WorkerPool::Destroy shouldn\\t throw an exception of type ' . get_class($e) . ' with message:' . $e->getMessage() . "\n" . $e->getTraceAsString()); } }