Instead of calling StopProxy::run() (synchronous) then StartProxy::run() (async), now we build a single command sequence that includes both stop and start phases. This creates one Activity immediately via remote_process(), so the UI receives the activity ID right away and can show logs in real-time from the very beginning of the restart operation. Key changes: - Removed dependency on StopProxy and StartProxy actions - Build combined command sequence inline in buildRestartCommands() - Use remote_process() directly which returns Activity immediately - Increased timeout from 60s to 120s to accommodate full restart - Activity ID dispatched to UI within milliseconds of job starting Flow is now: 1. Job starts → sets "restarting" status 2. Commands built synchronously (fast, no SSH) 3. remote_process() creates Activity and dispatches CoolifyTask job 4. Activity ID sent to UI immediately via WebSocket 5. UI opens activity monitor with real-time streaming logs 6. Logs show "Stopping proxy..." then "Starting proxy..." as they happen 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Jobs;
|
|
|
|
use App\Jobs\RestartProxyJob;
|
|
use App\Models\Server;
|
|
use Illuminate\Queue\Middleware\WithoutOverlapping;
|
|
use Mockery;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Unit tests for RestartProxyJob.
|
|
*
|
|
* These tests focus on testing the job's middleware configuration and constructor.
|
|
* Full integration tests for the job's handle() method are in tests/Feature/Proxy/
|
|
* because they require database and complex mocking of SchemalessAttributes.
|
|
*/
|
|
class RestartProxyJobTest extends TestCase
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
Mockery::close();
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_job_has_without_overlapping_middleware()
|
|
{
|
|
$server = Mockery::mock(Server::class);
|
|
$server->shouldReceive('getSchemalessAttributes')->andReturn([]);
|
|
$server->shouldReceive('getAttribute')->with('uuid')->andReturn('test-uuid');
|
|
|
|
$job = new RestartProxyJob($server);
|
|
$middleware = $job->middleware();
|
|
|
|
$this->assertCount(1, $middleware);
|
|
$this->assertInstanceOf(WithoutOverlapping::class, $middleware[0]);
|
|
}
|
|
|
|
public function test_job_has_correct_configuration()
|
|
{
|
|
$server = Mockery::mock(Server::class);
|
|
|
|
$job = new RestartProxyJob($server);
|
|
|
|
$this->assertEquals(1, $job->tries);
|
|
$this->assertEquals(120, $job->timeout);
|
|
$this->assertNull($job->activity_id);
|
|
}
|
|
|
|
public function test_job_stores_server()
|
|
{
|
|
$server = Mockery::mock(Server::class);
|
|
|
|
$job = new RestartProxyJob($server);
|
|
|
|
$this->assertSame($server, $job->server);
|
|
}
|
|
}
|