2025-11-10 10:11:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
2026-02-26 07:37:20 +00:00
|
|
|
use App\Enums\ProcessStatus;
|
2025-11-10 10:11:18 +00:00
|
|
|
use App\Jobs\CoolifyTask;
|
|
|
|
|
use App\Models\Server;
|
2026-02-26 07:37:20 +00:00
|
|
|
use App\Models\Team;
|
2025-11-10 10:11:18 +00:00
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
|
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
|
|
2026-02-26 07:37:20 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
|
$team = Team::factory()->create();
|
|
|
|
|
Server::factory()->create(['team_id' => $team->id]);
|
2025-11-10 10:11:18 +00:00
|
|
|
|
2026-02-26 07:37:20 +00:00
|
|
|
$this->activity = activity()
|
2025-11-10 10:11:18 +00:00
|
|
|
->withProperties([
|
2026-02-26 07:37:20 +00:00
|
|
|
'server_uuid' => Server::first()->uuid,
|
2025-11-10 10:11:18 +00:00
|
|
|
'command' => 'echo "test"',
|
|
|
|
|
'type' => 'inline',
|
2026-02-26 07:37:20 +00:00
|
|
|
'status' => ProcessStatus::QUEUED->value,
|
2025-11-10 10:11:18 +00:00
|
|
|
])
|
|
|
|
|
->event('inline')
|
|
|
|
|
->log('[]');
|
|
|
|
|
|
2026-02-26 07:37:20 +00:00
|
|
|
$this->job = new CoolifyTask(
|
|
|
|
|
activity: $this->activity,
|
2025-11-10 10:11:18 +00:00
|
|
|
ignore_errors: false,
|
|
|
|
|
call_event_on_finish: null,
|
2026-02-26 07:37:20 +00:00
|
|
|
call_event_data: null,
|
2025-11-10 10:11:18 +00:00
|
|
|
);
|
2026-02-26 07:37:20 +00:00
|
|
|
});
|
2025-11-10 10:11:18 +00:00
|
|
|
|
2026-02-26 07:37:20 +00:00
|
|
|
test('has correct retry configuration', function () {
|
|
|
|
|
expect($this->job->tries)->toBe(3)
|
|
|
|
|
->and($this->job->maxExceptions)->toBe(1)
|
|
|
|
|
->and($this->job->timeout)->toBe(600)
|
|
|
|
|
->and($this->job->backoff())->toBe([30, 90, 180]);
|
2025-11-10 10:11:18 +00:00
|
|
|
});
|
|
|
|
|
|
2026-02-26 07:37:20 +00:00
|
|
|
test('is queued on the high priority queue', function () {
|
|
|
|
|
expect($this->job->queue)->toBe('high');
|
|
|
|
|
});
|
2025-11-10 10:11:18 +00:00
|
|
|
|
2026-02-26 07:37:20 +00:00
|
|
|
test('marks activity as error on permanent failure', function () {
|
|
|
|
|
$exception = new \RuntimeException('SSH connection failed');
|
2025-11-10 10:11:18 +00:00
|
|
|
|
2026-02-26 07:37:20 +00:00
|
|
|
$this->job->failed($exception);
|
2025-11-10 10:11:18 +00:00
|
|
|
|
2026-02-26 07:37:20 +00:00
|
|
|
$this->activity->refresh();
|
|
|
|
|
$properties = $this->activity->properties;
|
|
|
|
|
|
|
|
|
|
expect($properties['status'])->toBe(ProcessStatus::ERROR->value)
|
|
|
|
|
->and($properties['error'])->toBe('SSH connection failed')
|
|
|
|
|
->and($properties)->toHaveKey('failed_at');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('marks activity as error with default message when exception is null', function () {
|
|
|
|
|
$this->job->failed(null);
|
|
|
|
|
|
|
|
|
|
$this->activity->refresh();
|
|
|
|
|
$properties = $this->activity->properties;
|
2025-11-10 10:11:18 +00:00
|
|
|
|
2026-02-26 07:37:20 +00:00
|
|
|
expect($properties['status'])->toBe(ProcessStatus::ERROR->value)
|
|
|
|
|
->and($properties['error'])->toBe('Job permanently failed');
|
2025-11-10 10:11:18 +00:00
|
|
|
});
|