Skip to content

Fix failing tests #1229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/SupervisorOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ class SupervisorOptions
*/
public $rest;

/**
* Indicates if the supervisor should auto-scale.
*
* @var bool
*/
public $autoScale;

/**
* Create a new worker options instance.
*
Expand Down
6 changes: 0 additions & 6 deletions tests/Feature/MasterSupervisorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,6 @@ public function test_supervisor_process_terminates_all_workers_and_exits_on_full
$master = new Fakes\MasterSupervisorWithFakeExit;
$master->working = true;

$repository = resolve(MasterSupervisorRepository::class);
$repository->forgetDelay = 1;

$master->persist();
$master->terminate();

Expand All @@ -219,9 +216,6 @@ public function test_supervisor_continues_termination_if_supervisors_take_too_lo
$master = new Fakes\MasterSupervisorWithFakeExit;
$master->working = true;

$repository = resolve(MasterSupervisorRepository::class);
$repository->forgetDelay = 1;

$master->supervisors = collect([new EternalSupervisor]);

$master->persist();
Expand Down
7 changes: 2 additions & 5 deletions tests/Feature/MonitorWaitTimesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Laravel\Horizon\Tests\Feature;

use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\Event;
use Laravel\Horizon\Contracts\MetricsRepository;
use Laravel\Horizon\Events\LongWaitDetected;
Expand All @@ -24,8 +23,7 @@ public function test_queues_with_long_waits_are_found()
]);
$this->app->instance(WaitTimeCalculator::class, $calc);

$listener = new MonitorWaitTimes(resolve(MetricsRepository::class));
$listener->lastMonitoredAt = CarbonImmutable::now()->subDay();
$listener = new MonitorWaitTimes(app(MetricsRepository::class));

$listener->handle();

Expand All @@ -46,8 +44,7 @@ public function test_queue_ignores_long_waits()
]);
$this->app->instance(WaitTimeCalculator::class, $calc);

$listener = new MonitorWaitTimes(resolve(MetricsRepository::class));
$listener->lastMonitoredAt = CarbonImmutable::now()->subDays(1);
$listener = new MonitorWaitTimes(app(MetricsRepository::class));

$listener->handle();

Expand Down
37 changes: 17 additions & 20 deletions tests/Feature/SupervisorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function test_supervisor_can_start_worker_process_with_given_options()
$supervisor->loop();

$this->wait(function () {
$this->assertSame('completed', resolve(JobRepository::class)->getRecent()[0]->status);
$this->assertSame('completed', app(JobRepository::class)->getRecent()[0]->status);
});

$this->assertCount(1, $supervisor->processes());
Expand Down Expand Up @@ -100,7 +100,7 @@ public function test_recent_jobs_are_correctly_maintained()
$id = Queue::push(new Jobs\BasicJob);
$this->assertSame(1, $this->recentJobs());

$this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions());
$this->supervisor = $supervisor = new Supervisor($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->supervisorOptions());
$this->supervisor = $supervisor = new Supervisor($this->supervisorOptions());
// Force underlying worker to fail...
WorkerCommandString::$command = 'php wrong.php';

Expand Down Expand Up @@ -146,7 +146,7 @@ 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->supervisorOptions());
$this->supervisor = $supervisor = new Fakes\SupervisorThatThrowsException($this->supervisorOptions());

$supervisor->loop();
}
Expand All @@ -161,7 +161,7 @@ public function test_supervisor_information_is_persisted()

$supervisor->loop();

$record = resolve(SupervisorRepository::class)->find($supervisor->name);
$record = app(SupervisorRepository::class)->find($supervisor->name);
$this->assertSame('running', $record->status);
$this->assertSame(2, collect($record->processes)->sum());
$this->assertSame(2, $record->processes['redis:default,another']);
Expand All @@ -171,20 +171,20 @@ public function test_supervisor_information_is_persisted()
$supervisor->pause();
$supervisor->loop();

$record = resolve(SupervisorRepository::class)->find($supervisor->name);
$record = app(SupervisorRepository::class)->find($supervisor->name);
$this->assertSame('paused', $record->status);
}

public function test_supervisor_repository_returns_null_if_no_supervisor_exists_with_given_name()
{
$repository = resolve(SupervisorRepository::class);
$repository = app(SupervisorRepository::class);

$this->assertNull($repository->find('nothing'));
}

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

$supervisor->scale(2);
$supervisor->loop();
Expand Down Expand Up @@ -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->supervisorOptions());
$this->supervisor = $supervisor = new Supervisor($this->supervisorOptions());

$supervisor->scale(1);
$supervisor->loop();
Expand Down Expand Up @@ -259,13 +259,13 @@ public function test_processes_can_be_paused_and_continued()
$this->assertTrue($supervisor->processPools[0]->working);

$this->wait(function () {
$this->assertSame('completed', resolve(JobRepository::class)->getRecent()[0]->status);
$this->assertSame('completed', app(JobRepository::class)->getRecent()[0]->status);
});
}

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

$supervisor->scale(1);
$supervisor->loop();
Expand Down Expand Up @@ -334,10 +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->supervisorOptions());

$repository = resolve(SupervisorRepository::class);
$repository->forgetDelay = 1;
$this->supervisor = $supervisor = new Fakes\SupervisorWithFakeExit($this->supervisorOptions());

$supervisor->scale(1);
usleep(100 * 1000);
Expand All @@ -348,27 +345,27 @@ public function test_supervisor_process_terminates_all_workers_and_exits_on_full
$this->assertTrue($supervisor->exited);

// Assert that the supervisor is removed...
$this->assertNull(resolve(SupervisorRepository::class)->find($supervisor->name));
$this->assertNull(app(SupervisorRepository::class)->find($supervisor->name));
}

public function test_supervisor_loop_processes_pending_supervisor_commands()
{
$this->app->singleton(Commands\FakeCommand::class);

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

$supervisor->scale(1);
usleep(100 * 1000);

resolve(HorizonCommandQueue::class)->push(
app(HorizonCommandQueue::class)->push(
$supervisor->name, Commands\FakeCommand::class, ['foo' => 'bar']
);

// Loop twice to make sure command is only called once...
$supervisor->loop();
$supervisor->loop();

$command = resolve(Commands\FakeCommand::class);
$command = app(Commands\FakeCommand::class);

$this->assertSame(1, $command->processCount);
$this->assertEquals($supervisor, $command->supervisor);
Expand All @@ -384,7 +381,7 @@ public function test_supervisor_should_start_paused_workers_when_paused_and_scal
$supervisor->scale(1);
usleep(100 * 1000);

resolve(HorizonCommandQueue::class)->push(
app(HorizonCommandQueue::class)->push(
$supervisor->name, Scale::class, ['scale' => 2]
);
$supervisor->pause();
Expand Down