mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-07 17:02:34 +00:00
Add workers to servers (#547)
This commit is contained in:
@ -2,25 +2,25 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\QueueStatus;
|
||||
use App\Enums\WorkerStatus;
|
||||
use App\Facades\SSH;
|
||||
use App\Models\Queue;
|
||||
use App\Models\Site;
|
||||
use App\Web\Pages\Servers\Sites\Pages\Queues\Index;
|
||||
use App\Web\Pages\Servers\Sites\Pages\Queues\Widgets\QueuesList;
|
||||
use App\Models\Worker;
|
||||
use App\Web\Pages\Servers\Sites\Pages\Workers\Index;
|
||||
use App\Web\Pages\Servers\Sites\Pages\Workers\Widgets\WorkersList;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class QueuesTest extends TestCase
|
||||
class WorkersTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_see_queues()
|
||||
public function test_see_workers(): void
|
||||
{
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$queue = Queue::factory()->create([
|
||||
$worker = Worker::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
]);
|
||||
@ -32,33 +32,33 @@ public function test_see_queues()
|
||||
])
|
||||
)
|
||||
->assertSuccessful()
|
||||
->assertSee($queue->command);
|
||||
->assertSee($worker->command);
|
||||
}
|
||||
|
||||
public function test_delete_queue()
|
||||
public function test_delete_worker(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$queue = Queue::factory()->create([
|
||||
$worker = Worker::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
]);
|
||||
|
||||
Livewire::test(QueuesList::class, [
|
||||
Livewire::test(WorkersList::class, [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
])
|
||||
->callTableAction('delete', $queue->id)
|
||||
->callTableAction('delete', $worker->id)
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('queues', [
|
||||
'id' => $queue->id,
|
||||
$this->assertDatabaseMissing('workers', [
|
||||
'id' => $worker->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_create_queue()
|
||||
public function test_create_worker(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
@ -69,7 +69,7 @@ public function test_create_queue()
|
||||
'site' => $this->site,
|
||||
])
|
||||
->callAction('create', [
|
||||
'command' => 'php artisan queue:work',
|
||||
'command' => 'php artisan worker:work',
|
||||
'user' => 'vito',
|
||||
'auto_start' => 1,
|
||||
'auto_restart' => 1,
|
||||
@ -77,19 +77,19 @@ public function test_create_queue()
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('queues', [
|
||||
$this->assertDatabaseHas('workers', [
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
'command' => 'php artisan queue:work',
|
||||
'command' => 'php artisan worker:work',
|
||||
'user' => 'vito',
|
||||
'auto_start' => 1,
|
||||
'auto_restart' => 1,
|
||||
'numprocs' => 1,
|
||||
'status' => QueueStatus::RUNNING,
|
||||
'status' => WorkerStatus::RUNNING,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_create_queue_as_isolated_user(): void
|
||||
public function test_create_worker_as_isolated_user(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
@ -111,7 +111,7 @@ public function test_create_queue_as_isolated_user(): void
|
||||
])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('queues', [
|
||||
$this->assertDatabaseHas('workers', [
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
'command' => 'php artisan queue:work',
|
||||
@ -119,11 +119,11 @@ public function test_create_queue_as_isolated_user(): void
|
||||
'auto_start' => 1,
|
||||
'auto_restart' => 1,
|
||||
'numprocs' => 1,
|
||||
'status' => QueueStatus::RUNNING,
|
||||
'status' => WorkerStatus::RUNNING,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_cannot_create_queue_as_invalid_user(): void
|
||||
public function test_cannot_create_worker_as_invalid_user(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
@ -142,14 +142,14 @@ public function test_cannot_create_queue_as_invalid_user(): void
|
||||
])
|
||||
->assertHasActionErrors();
|
||||
|
||||
$this->assertDatabaseMissing('queues', [
|
||||
$this->assertDatabaseMissing('workers', [
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
'user' => 'example',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_cannot_create_queue_on_another_sites_user(): void
|
||||
public function test_cannot_create_worker_on_another_sites_user(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
@ -173,85 +173,85 @@ public function test_cannot_create_queue_on_another_sites_user(): void
|
||||
])
|
||||
->assertHasActionErrors();
|
||||
|
||||
$this->assertDatabaseMissing('queues', [
|
||||
$this->assertDatabaseMissing('workers', [
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
'user' => 'example',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_start_queue(): void
|
||||
public function test_start_worker(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$queue = Queue::factory()->create([
|
||||
$worker = Worker::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
'status' => QueueStatus::STOPPED,
|
||||
'status' => WorkerStatus::STOPPED,
|
||||
]);
|
||||
|
||||
Livewire::test(QueuesList::class, [
|
||||
Livewire::test(WorkersList::class, [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
])
|
||||
->callTableAction('start', $queue->id)
|
||||
->callTableAction('start', $worker->id)
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('queues', [
|
||||
'id' => $queue->id,
|
||||
'status' => QueueStatus::RUNNING,
|
||||
$this->assertDatabaseHas('workers', [
|
||||
'id' => $worker->id,
|
||||
'status' => WorkerStatus::RUNNING,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_stop_queue(): void
|
||||
public function test_stop_worker(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$queue = Queue::factory()->create([
|
||||
$worker = Worker::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
'status' => QueueStatus::RUNNING,
|
||||
'status' => WorkerStatus::RUNNING,
|
||||
]);
|
||||
|
||||
Livewire::test(QueuesList::class, [
|
||||
Livewire::test(WorkersList::class, [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
])
|
||||
->callTableAction('stop', $queue->id)
|
||||
->callTableAction('stop', $worker->id)
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('queues', [
|
||||
'id' => $queue->id,
|
||||
'status' => QueueStatus::STOPPED,
|
||||
$this->assertDatabaseHas('workers', [
|
||||
'id' => $worker->id,
|
||||
'status' => WorkerStatus::STOPPED,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_restart_queue(): void
|
||||
public function test_restart_worker(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$queue = Queue::factory()->create([
|
||||
$worker = Worker::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
'status' => QueueStatus::RUNNING,
|
||||
'status' => WorkerStatus::RUNNING,
|
||||
]);
|
||||
|
||||
Livewire::test(QueuesList::class, [
|
||||
Livewire::test(WorkersList::class, [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
])
|
||||
->callTableAction('restart', $queue->id)
|
||||
->callTableAction('restart', $worker->id)
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('queues', [
|
||||
'id' => $queue->id,
|
||||
'status' => QueueStatus::RUNNING,
|
||||
$this->assertDatabaseHas('workers', [
|
||||
'id' => $worker->id,
|
||||
'status' => WorkerStatus::RUNNING,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -261,17 +261,17 @@ public function test_show_logs(): void
|
||||
|
||||
$this->actingAs($this->user);
|
||||
|
||||
$queue = Queue::factory()->create([
|
||||
$worker = Worker::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
'status' => QueueStatus::RUNNING,
|
||||
'status' => WorkerStatus::RUNNING,
|
||||
]);
|
||||
|
||||
Livewire::test(QueuesList::class, [
|
||||
Livewire::test(WorkersList::class, [
|
||||
'server' => $this->server,
|
||||
'site' => $this->site,
|
||||
])
|
||||
->callTableAction('logs', $queue->id)
|
||||
->callTableAction('logs', $worker->id)
|
||||
->assertSuccessful();
|
||||
}
|
||||
}
|
@ -6,8 +6,8 @@
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Facades\SSH;
|
||||
use App\Models\Database;
|
||||
use App\Models\Queue;
|
||||
use App\Models\Service;
|
||||
use App\Models\Worker;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tests\TestCase;
|
||||
@ -74,7 +74,7 @@ public function test_cannot_uninstall_supervisor(): void
|
||||
{
|
||||
SSH::fake();
|
||||
|
||||
Queue::factory()->create([
|
||||
Worker::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'site_id' => $this->site->id,
|
||||
]);
|
||||
|
Reference in New Issue
Block a user