Correctly handle schedule task deletion and avoid errors; closes #2534

This commit is contained in:
Dane Everitt 2020-10-22 20:54:58 -07:00
parent e1fa6d4e55
commit 65d04d0c05
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 128 additions and 5 deletions

View file

@ -81,6 +81,37 @@ class ProcessScheduleServiceTest extends IntegrationTestCase
$this->assertDatabaseHas('tasks', ['id' => $task->id, 'is_queued' => true]);
}
/**
* Test that even if a schedule's task sequence gets messed up the first task based on
* the ascending order of tasks is used.
*
* @see https://github.com/pterodactyl/panel/issues/2534
*/
public function testFirstSequenceTaskIsFound()
{
$this->swap(Dispatcher::class, $dispatcher = Mockery::mock(Dispatcher::class));
$server = $this->createServerModel();
/** @var \Pterodactyl\Models\Schedule $schedule */
$schedule = factory(Schedule::class)->create(['server_id' => $server->id]);
/** @var \Pterodactyl\Models\Task $task */
$task2 = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 4]);
$task = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 2]);
$task3 = factory(Task::class)->create(['schedule_id' => $schedule->id, 'sequence_id' => 3]);
$dispatcher->expects('dispatch')->with(Mockery::on(function (RunTaskJob $job) use ($task) {
return $task->id === $job->task->id;
}));
$this->getService()->handle($schedule);
$this->assertDatabaseHas('schedules', ['id' => $schedule->id, 'is_processing' => true]);
$this->assertDatabaseHas('tasks', ['id' => $task->id, 'is_queued' => true]);
$this->assertDatabaseHas('tasks', ['id' => $task2->id, 'is_queued' => false]);
$this->assertDatabaseHas('tasks', ['id' => $task3->id, 'is_queued' => false]);
}
/**
* @return array
*/