connection = Server::get(IDBConnection::class); $this->registry = Server::get(JobClassesRegistry::class); $this->runs = new JobRuns( $this->connection, Server::get(ISnowflakeGenerator::class), Server::get(ISnowflakeDecoder::class), $this->registry, $this->createMock(LoggerInterface::class), ); } public function testJobStarted(): void { $myPid = 1337; $myClass = DummyJob::class; $runId = $this->runs->started($this->registry->getId(DummyJob::class), $myPid); $this->assertGreaterThan(0, $runId); } public function testJobSucceeded(): void { $myPid = 1337; $myClass = DummyJob::class; $runId = $this->runs->started($this->registry->getId(DummyJob::class), $myPid); $result = $this->runs->finished($runId, 12, 9876543); $this->assertTrue($result); } public function testJobFailed(): void { $myPid = 1337; $myClass = DummyJob::class; $runId = $this->runs->started($this->registry->getId(DummyJob::class), $myPid); $result = $this->runs->finished($runId, 13, 87654321, JobStatus::FAILED); $this->assertTrue($result); } public function testRunningJobs(): void { $myPid = 1337; $myClass = DummyJob::class; $runId = $this->runs->started($this->registry->getId(DummyJob::class), $myPid); $runningJobs = 0; foreach ($this->runs->runningJobs() as $job) { $this->assertInstanceOf(JobRun::class, $job); ++$runningJobs; } $this->assertGreaterThan(0, $runningJobs); } public function testCompletedJobs(): void { $myPid = 1337; $myClass = DummyJob::class; $runId = $this->runs->started($this->registry->getId(DummyJob::class), $myPid); $this->runs->finished($runId, 12345, 67890 * 1024, JobStatus::FAILED); $runId = $this->runs->started($this->registry->getId(DummyJob::class), $myPid); $this->runs->finished($runId, 12345, 67890 * 1024, JobStatus::SUCCEEDED); $runId = $this->runs->started($this->registry->getId(DummyJob::class), $myPid); $this->runs->finished($runId, 12345, 67890 * 1024, JobStatus::CRASHED); $completedJobs = 0; foreach ($this->runs->runningJobs() as $job) { $this->assertInstanceOf(JobRun::class, $job); ++$completedJobs; } $this->assertGreaterThan(0, $completedJobs); } }