added a help system, replaced the words "tenant" and "Pwa" with better alternatives. corrected and implemented cron jobs. prepared going live on a coolify-powered system.
This commit is contained in:
78
tests/Feature/Console/CheckUploadQueuesCommandTest.php
Normal file
78
tests/Feature/Console/CheckUploadQueuesCommandTest.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Console;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\EventMediaAsset;
|
||||
use App\Models\MediaStorageTarget;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Queue\QueueManager;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CheckUploadQueuesCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_queue_health_snapshot_detects_alerts(): void
|
||||
{
|
||||
config()->set('storage-monitor.queue_health.thresholds', [
|
||||
'media-storage' => ['warning' => 10, 'critical' => 20],
|
||||
]);
|
||||
config()->set('storage-monitor.queue_health.stalled_minutes', 5);
|
||||
config()->set('storage-monitor.queue_health.cache_minutes', 5);
|
||||
|
||||
$manager = Mockery::mock(QueueManager::class);
|
||||
$connection = Mockery::mock(\Illuminate\Contracts\Queue\Queue::class);
|
||||
$manager->shouldReceive('connection')->with(config('queue.default'))->andReturn($connection);
|
||||
$connection->shouldReceive('size')->with('media-storage')->andReturn(25);
|
||||
$this->app->instance(QueueManager::class, $manager);
|
||||
|
||||
DB::table('failed_jobs')->insert([
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'connection' => 'sync',
|
||||
'queue' => 'media-storage',
|
||||
'payload' => '{}',
|
||||
'exception' => 'Test failure',
|
||||
'failed_at' => now(),
|
||||
]);
|
||||
|
||||
$target = MediaStorageTarget::create([
|
||||
'key' => 'local-hot',
|
||||
'name' => 'Local Hot',
|
||||
'driver' => 'local',
|
||||
'config' => ['monitor_path' => storage_path('app')],
|
||||
'is_hot' => true,
|
||||
'is_default' => true,
|
||||
'is_active' => true,
|
||||
'priority' => 100,
|
||||
]);
|
||||
|
||||
$event = Event::factory()->create();
|
||||
$asset = EventMediaAsset::create([
|
||||
'event_id' => $event->id,
|
||||
'media_storage_target_id' => $target->id,
|
||||
'variant' => 'original',
|
||||
'disk' => 'local-hot',
|
||||
'path' => 'events/'.$event->id.'/pending.jpg',
|
||||
'size_bytes' => 512,
|
||||
'status' => 'pending',
|
||||
]);
|
||||
EventMediaAsset::whereKey($asset->id)->update([
|
||||
'created_at' => now()->subMinutes(10),
|
||||
'updated_at' => now()->subMinutes(10),
|
||||
]);
|
||||
|
||||
$this->artisan('storage:check-upload-queues')
|
||||
->expectsOutput('Checked 1 queue(s); 3 alert(s).')
|
||||
->assertExitCode(0);
|
||||
|
||||
$snapshot = Cache::get('storage:queue-health:last');
|
||||
$this->assertNotNull($snapshot);
|
||||
$this->assertSame('critical', $snapshot['queues'][0]['severity']);
|
||||
$this->assertGreaterThanOrEqual(1, count($snapshot['alerts']));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user