Skip to content

Commit

Permalink
Merge pull request #676 from driesvints/fix-tests
Browse files Browse the repository at this point in the history
[3.x] Fix test suite
  • Loading branch information
taylorotwell authored Sep 27, 2019
2 parents 8253857 + 7b3ec15 commit 8fe8fae
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
24 changes: 17 additions & 7 deletions tests/Feature/MasterSupervisorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function test_master_process_marks_clean_exits_as_dead_and_removes_them()
{
$master = new MasterSupervisor;
$master->working = true;
$master->supervisors[] = $supervisorProcess = new SupervisorProcess($this->options(), $process = Mockery::mock());
$master->supervisors[] = $supervisorProcess = new SupervisorProcess(
$this->supervisorOptions(), $process = Mockery::mock()
);

$process->shouldReceive('isStarted')->andReturn(true);
$process->shouldReceive('isRunning')->andReturn(false);
Expand All @@ -54,7 +56,9 @@ public function test_master_process_marks_duplicates_as_dead_and_removes_them()
{
$master = new MasterSupervisor;
$master->working = true;
$master->supervisors[] = $supervisorProcess = new SupervisorProcess($this->options(), $process = Mockery::mock());
$master->supervisors[] = $supervisorProcess = new SupervisorProcess(
$this->supervisorOptions(), $process = Mockery::mock()
);

$process->shouldReceive('isStarted')->andReturn(true);
$process->shouldReceive('isRunning')->andReturn(false);
Expand All @@ -70,7 +74,9 @@ public function test_master_process_restarts_unexpected_exits()
{
$master = new MasterSupervisor;
$master->working = true;
$master->supervisors[] = $supervisorProcess = new SupervisorProcessWithFakeRestart($this->options(), $process = Mockery::mock());
$master->supervisors[] = $supervisorProcess = new SupervisorProcessWithFakeRestart(
$this->supervisorOptions(), $process = Mockery::mock()
);

$process->shouldReceive('isStarted')->andReturn(true);
$process->shouldReceive('isRunning')->andReturn(false);
Expand All @@ -95,7 +101,9 @@ public function test_master_process_restarts_processes_that_never_started()
{
$master = new MasterSupervisor;
$master->working = true;
$master->supervisors[] = $supervisorProcess = new SupervisorProcessWithFakeRestart($this->options(), $process = Mockery::mock());
$master->supervisors[] = $supervisorProcess = new SupervisorProcessWithFakeRestart(
$this->supervisorOptions(), $process = Mockery::mock()
);

$process->shouldReceive('isStarted')->andReturn(false);

Expand All @@ -109,7 +117,9 @@ public function test_master_process_restarts_processes_that_never_started()
public function test_master_process_starts_unstarted_processes_when_unpaused()
{
$master = new MasterSupervisor;
$master->supervisors[] = $supervisorProcess = new SupervisorProcessWithFakeRestart($this->options(), $process = Mockery::mock());
$master->supervisors[] = $supervisorProcess = new SupervisorProcessWithFakeRestart(
$this->supervisorOptions(), $process = Mockery::mock()
);

$process->shouldReceive('isStarted')->andReturn(false);
$process->shouldReceive('isRunning')->andReturn(false);
Expand Down Expand Up @@ -147,7 +157,7 @@ public function test_master_process_information_is_persisted()
{
$master = new MasterSupervisor;
$master->working = true;
$master->supervisors[] = new SupervisorProcess($this->options(), $process = Mockery::mock());
$master->supervisors[] = new SupervisorProcess($this->supervisorOptions(), $process = Mockery::mock());
$process->shouldReceive('isStarted')->andReturn(true);
$process->shouldReceive('isRunning')->andReturn(true);
$process->shouldReceive('signal');
Expand Down Expand Up @@ -220,7 +230,7 @@ public function test_supervisor_continues_termination_if_supervisors_take_too_lo
$this->assertTrue($master->exited);
}

protected function options()
protected function supervisorOptions()
{
return tap(new SupervisorOptions(MasterSupervisor::name().':name', 'redis'), function ($options) {
$phpBinary = PhpBinary::path();
Expand Down
44 changes: 22 additions & 22 deletions tests/Feature/SupervisorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function test_supervisor_can_start_worker_process_with_given_options()
Queue::push(new Jobs\BasicJob);
$this->assertEquals(1, $this->recentJobs());

$this->supervisor = $supervisor = new Supervisor($this->options());
$this->supervisor = $supervisor = new Supervisor($this->supervisorOptions());

$supervisor->scale(1);
$supervisor->loop();
Expand All @@ -74,7 +74,7 @@ public function test_supervisor_can_start_worker_process_with_given_options()

public function test_supervisor_starts_multiple_pools_when_balancing()
{
$options = $this->options();
$options = $this->supervisorOptions();
$options->balance = 'simple';
$options->queue = 'first,second';
$this->supervisor = $supervisor = new Supervisor($options);
Expand All @@ -100,7 +100,7 @@ public function test_recent_jobs_are_correctly_maintained()
$id = Queue::push(new Jobs\BasicJob);
$this->assertEquals(1, $this->recentJobs());

$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());

$supervisor->scale(1);
$supervisor->loop();
Expand All @@ -116,7 +116,7 @@ public function test_recent_jobs_are_correctly_maintained()

public function test_supervisor_monitors_worker_processes()
{
$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());
// Force underlying worker to fail...
WorkerCommandString::$command = 'php wrong.php';

Expand Down Expand Up @@ -146,14 +146,14 @@ public function test_exceptions_are_caught_and_handled_during_loop()
$exceptions->shouldReceive('report')->once();
$this->app->instance(ExceptionHandler::class, $exceptions);

$this->supervisor = $supervisor = new Fakes\SupervisorThatThrowsException($options = $this->options());
$this->supervisor = $supervisor = new Fakes\SupervisorThatThrowsException($options = $this->supervisorOptions());

$supervisor->loop();
}

public function test_supervisor_information_is_persisted()
{
$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());
$options->queue = 'default,another';

$supervisor->scale(2);
Expand Down Expand Up @@ -184,7 +184,7 @@ public function test_supervisor_repository_returns_null_if_no_supervisor_exists_

public function test_processes_can_be_scaled_up()
{
$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());

$supervisor->scale(2);
$supervisor->loop();
Expand All @@ -197,7 +197,7 @@ public function test_processes_can_be_scaled_up()

public function test_processes_can_be_scaled_down()
{
$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());
$options->sleep = 0;

$supervisor->scale(3);
Expand All @@ -221,7 +221,7 @@ public function test_processes_can_be_scaled_down()

public function test_supervisor_can_restart_processes()
{
$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());

$supervisor->scale(1);
$supervisor->loop();
Expand All @@ -237,7 +237,7 @@ public function test_supervisor_can_restart_processes()

public function test_processes_can_be_paused_and_continued()
{
$options = $this->options();
$options = $this->supervisorOptions();
$options->sleep = 0;
$this->supervisor = $supervisor = new Supervisor($options);

Expand Down Expand Up @@ -265,7 +265,7 @@ public function test_processes_can_be_paused_and_continued()

public function test_dead_processes_are_not_restarted_when_paused()
{
$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());

$supervisor->scale(1);
$supervisor->loop();
Expand All @@ -283,7 +283,7 @@ public function test_dead_processes_are_not_restarted_when_paused()

public function test_supervisor_processes_can_be_terminated()
{
$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());
$options->sleep = 0;

$supervisor->scale(1);
Expand All @@ -303,7 +303,7 @@ public function test_supervisor_processes_can_be_terminated()

public function test_supervisor_can_prune_terminating_processes_and_return_total_process_count()
{
$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());
$options->sleep = 0;

$supervisor->scale(1);
Expand All @@ -317,7 +317,7 @@ public function test_supervisor_can_prune_terminating_processes_and_return_total

public function test_terminating_processes_that_are_stuck_are_hard_stopped()
{
$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());
$options->timeout = 0;
$options->sleep = 0;

Expand All @@ -334,7 +334,7 @@ public function test_terminating_processes_that_are_stuck_are_hard_stopped()

public function test_supervisor_process_terminates_all_workers_and_exits_on_full_termination()
{
$this->supervisor = $supervisor = new Fakes\SupervisorWithFakeExit($options = $this->options());
$this->supervisor = $supervisor = new Fakes\SupervisorWithFakeExit($options = $this->supervisorOptions());

$repository = resolve(SupervisorRepository::class);
$repository->forgetDelay = 1;
Expand All @@ -355,7 +355,7 @@ public function test_supervisor_loop_processes_pending_supervisor_commands()
{
$this->app->singleton(Commands\FakeCommand::class);

$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());

$supervisor->scale(1);
usleep(100 * 1000);
Expand All @@ -377,7 +377,7 @@ public function test_supervisor_loop_processes_pending_supervisor_commands()

public function test_supervisor_should_start_paused_workers_when_paused_and_scaling()
{
$options = $this->options();
$options = $this->supervisorOptions();
$options->sleep = 0;
$this->supervisor = $supervisor = new Supervisor($options);

Expand All @@ -402,7 +402,7 @@ public function test_supervisor_should_start_paused_workers_when_paused_and_scal

public function test_auto_scaler_is_called_on_loop_when_auto_scaling()
{
$options = $this->options();
$options = $this->supervisorOptions();
$options->autoScale = true;
$this->supervisor = $supervisor = new Supervisor($options);

Expand All @@ -425,7 +425,7 @@ public function test_supervisor_with_duplicate_name_cant_be_started()
{
$this->expectException(Exception::class);

$options = $this->options();
$options = $this->supervisorOptions();
$this->supervisor = $supervisor = new Supervisor($options);
$supervisor->persist();
$anotherSupervisor = new Supervisor($options);
Expand All @@ -436,7 +436,7 @@ public function test_supervisor_with_duplicate_name_cant_be_started()
public function test_supervisor_processes_can_be_counted_externally()
{
SystemProcessCounter::$command = 'worker.php';
$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());

$supervisor->scale(3);
$supervisor->loop();
Expand All @@ -449,7 +449,7 @@ public function test_supervisor_processes_can_be_counted_externally()
public function test_supervisor_does_not_start_workers_until_looped_and_active()
{
SystemProcessCounter::$command = 'worker.php';
$this->supervisor = $supervisor = new Supervisor($options = $this->options());
$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());

$supervisor->scale(3);

Expand All @@ -472,7 +472,7 @@ public function test_supervisor_does_not_start_workers_until_looped_and_active()
});
}

protected function options()
public function supervisorOptions()
{
return tap(new SupervisorOptions(MasterSupervisor::name().':name', 'redis'), function ($options) {
$options->directory = realpath(__DIR__.'/../');
Expand Down
10 changes: 0 additions & 10 deletions tests/Feature/WaitTimeCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Contracts\Queue\Factory as QueueFactory;
use Laravel\Horizon\Contracts\MetricsRepository;
use Laravel\Horizon\Contracts\SupervisorRepository;
use Laravel\Horizon\SupervisorOptions;
use Laravel\Horizon\Tests\IntegrationTest;
use Laravel\Horizon\WaitTimeCalculator;
use Mockery;
Expand Down Expand Up @@ -166,13 +165,4 @@ protected function with_scenario(array $supervisorSettings, array $queues)

return new WaitTimeCalculator($queue, $supervisors, $metrics);
}

protected function options()
{
return tap(new SupervisorOptions('test-supervisor', 'redis'), function ($options) {
$options->balance = true;
$options->queue = 'test-queue,test-queue-2';
$options->directory = realpath(__DIR__.'/../');
});
}
}

0 comments on commit 8fe8fae

Please sign in to comment.