Files
coolify/tests/Feature/PushServerUpdateJobTest.php
T
Andras Bacsai 626cfb4a22 fix(sentinel): reduce resource churn from health flaps
Ignore health status changes in Sentinel push deduplication when the container lifecycle state is unchanged.

Scope stale resource checks to Sentinel servers whose heartbeat is stale, and avoid refreshing resource last_online_at on unchanged statuses.
2026-05-27 16:48:38 +02:00

84 lines
2.6 KiB
PHP

<?php
use App\Jobs\PushServerUpdateJob;
use App\Models\Server;
use App\Models\Service;
use App\Models\ServiceApplication;
use App\Models\Team;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
test('containers with empty service subId are skipped', function () {
$team = Team::factory()->create();
$server = Server::factory()->create(['team_id' => $team->id]);
$service = Service::factory()->create([
'server_id' => $server->id,
]);
$serviceApp = ServiceApplication::create([
'service_id' => $service->id,
'uuid' => (string) str()->uuid(),
'name' => 'app-'.str()->random(8),
]);
$data = [
'containers' => [
[
'name' => 'test-container',
'state' => 'running',
'health_status' => 'healthy',
'labels' => [
'coolify.managed' => true,
'coolify.serviceId' => (string) $service->id,
'coolify.service.subType' => 'application',
'coolify.service.subId' => '',
],
],
],
];
$job = new PushServerUpdateJob($server, $data);
// Run handle - should not throw a PDOException about empty bigint
$job->handle();
// The empty subId container should have been skipped
expect($job->foundServiceApplicationIds)->not->toContain('');
expect($job->serviceContainerStatuses)->toBeEmpty();
});
test('containers with valid service subId are processed', function () {
$team = Team::factory()->create();
$server = Server::factory()->create(['team_id' => $team->id]);
$service = Service::factory()->create([
'server_id' => $server->id,
]);
$serviceApp = ServiceApplication::create([
'service_id' => $service->id,
'uuid' => (string) str()->uuid(),
'name' => 'app-'.str()->random(8),
]);
$data = [
'containers' => [
[
'name' => 'test-container',
'state' => 'running',
'health_status' => 'healthy',
'labels' => [
'coolify.managed' => true,
'coolify.serviceId' => (string) $service->id,
'coolify.service.subType' => 'application',
'coolify.service.subId' => (string) $serviceApp->id,
'com.docker.compose.service' => 'myapp',
],
],
],
];
$job = new PushServerUpdateJob($server, $data);
$job->handle();
expect($job->foundServiceApplicationIds)->toContain((string) $serviceApp->id);
});