From 58ad9a96bc1277d95bc7095063430cca882702e1 Mon Sep 17 00:00:00 2001 From: "Chun-Sheng, Li" Date: Mon, 7 Sep 2020 10:50:58 +0800 Subject: [PATCH] Improve assertions (#884) --- tests/Controller/MonitoringControllerTest.php | 12 ++-- tests/Feature/AddSupervisorTest.php | 2 +- tests/Feature/AutoScalerTest.php | 62 +++++++++---------- tests/Feature/FailedJobTest.php | 6 +- tests/Feature/JobRetrievalTest.php | 14 ++--- tests/Feature/MasterSupervisorTest.php | 4 +- tests/Feature/MetricsTest.php | 36 +++++------ tests/Feature/MonitoringTest.php | 10 +-- tests/Feature/ProvisioningPlanTest.php | 12 ++-- tests/Feature/QueueProcessingTest.php | 8 +-- tests/Feature/RedisJobRepositoryTest.php | 2 +- tests/Feature/RedisPrefixTest.php | 2 +- tests/Feature/RetryJobTest.php | 6 +- tests/Feature/SupervisorCommandTest.php | 2 +- tests/Feature/SupervisorTest.php | 34 +++++----- tests/Feature/TagRepositoryTest.php | 8 +-- tests/Feature/WaitTimeCalculatorTest.php | 4 +- 17 files changed, 112 insertions(+), 112 deletions(-) diff --git a/tests/Controller/MonitoringControllerTest.php b/tests/Controller/MonitoringControllerTest.php index 73e8bd50..d5969f8e 100644 --- a/tests/Controller/MonitoringControllerTest.php +++ b/tests/Controller/MonitoringControllerTest.php @@ -51,8 +51,8 @@ public function test_monitored_jobs_can_be_paginated_by_tag() $results = $response->original['jobs']; $this->assertCount(25, $results); - $this->assertEquals(49, $results[0]->id); - $this->assertEquals(25, $results[24]->id); + $this->assertSame('49', $results[0]->id); + $this->assertSame('25', $results[24]->id); // Paginate second set... $response = $this->actingAs(new Fakes\User) @@ -61,10 +61,10 @@ public function test_monitored_jobs_can_be_paginated_by_tag() $results = $response->original['jobs']; $this->assertCount(25, $results); - $this->assertEquals(24, $results[0]->id); - $this->assertEquals(0, $results[24]->id); - $this->assertEquals(25, $results[0]->index); - $this->assertEquals(49, $results[24]->index); + $this->assertSame('24', $results[0]->id); + $this->assertSame('0', $results[24]->id); + $this->assertSame('25', $results[0]->index); + $this->assertSame(49, $results[24]->index); } public function test_can_paginate_where_jobs_dont_exist() diff --git a/tests/Feature/AddSupervisorTest.php b/tests/Feature/AddSupervisorTest.php index d3c6ad02..411a6bba 100644 --- a/tests/Feature/AddSupervisorTest.php +++ b/tests/Feature/AddSupervisorTest.php @@ -27,7 +27,7 @@ public function test_add_supervisor_command_creates_new_supervisor_on_master_pro $this->assertCount(1, $master->supervisors); - $this->assertEquals( + $this->assertSame( 'exec '.$phpBinary.' artisan horizon:supervisor my-supervisor redis --delay=0 --memory=128 --queue="default" --sleep=3 --timeout=60 --tries=0 --balance=off --max-processes=1 --min-processes=1 --nice=0', $master->supervisors->first()->process->getCommandLine() ); diff --git a/tests/Feature/AutoScalerTest.php b/tests/Feature/AutoScalerTest.php index a841fb31..06712811 100644 --- a/tests/Feature/AutoScalerTest.php +++ b/tests/Feature/AutoScalerTest.php @@ -22,24 +22,24 @@ public function test_scaler_attempts_to_get_closer_to_proper_balance_on_each_ite $scaler->scale($supervisor); - $this->assertEquals(11, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(9, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(11, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(9, $supervisor->processPools['second']->totalProcessCount()); $scaler->scale($supervisor); - $this->assertEquals(12, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(8, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(12, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(8, $supervisor->processPools['second']->totalProcessCount()); $scaler->scale($supervisor); - $this->assertEquals(13, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(7, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(13, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(7, $supervisor->processPools['second']->totalProcessCount()); // Asset scaler stays at target values... $scaler->scale($supervisor); - $this->assertEquals(13, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(7, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(13, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(7, $supervisor->processPools['second']->totalProcessCount()); } public function test_balance_stays_even_when_queue_is_empty() @@ -51,23 +51,23 @@ public function test_balance_stays_even_when_queue_is_empty() $scaler->scale($supervisor); - $this->assertEquals(4, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(4, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(4, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(4, $supervisor->processPools['second']->totalProcessCount()); $scaler->scale($supervisor); - $this->assertEquals(3, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(3, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(3, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(3, $supervisor->processPools['second']->totalProcessCount()); $scaler->scale($supervisor); - $this->assertEquals(2, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(2, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(2, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(2, $supervisor->processPools['second']->totalProcessCount()); $scaler->scale($supervisor); - $this->assertEquals(1, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(1, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(1, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(1, $supervisor->processPools['second']->totalProcessCount()); } public function test_balancer_assigns_more_processes_on_busy_queue() @@ -80,27 +80,27 @@ public function test_balancer_assigns_more_processes_on_busy_queue() $scaler->scale($supervisor); $scaler->scale($supervisor); - $this->assertEquals(3, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(1, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(3, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(1, $supervisor->processPools['second']->totalProcessCount()); $scaler->scale($supervisor); $scaler->scale($supervisor); - $this->assertEquals(5, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(1, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(5, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(1, $supervisor->processPools['second']->totalProcessCount()); $scaler->scale($supervisor); $scaler->scale($supervisor); - $this->assertEquals(7, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(1, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(7, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(1, $supervisor->processPools['second']->totalProcessCount()); $scaler->scale($supervisor); $scaler->scale($supervisor); $scaler->scale($supervisor); - $this->assertEquals(9, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(1, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(9, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(1, $supervisor->processPools['second']->totalProcessCount()); } public function test_balancing_a_single_queue_assigns_it_the_min_workers_with_empty_queue() @@ -110,7 +110,7 @@ public function test_balancing_a_single_queue_assigns_it_the_min_workers_with_em ]); $scaler->scale($supervisor); - $this->assertEquals(1, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(1, $supervisor->processPools['first']->totalProcessCount()); } public function test_scaler_will_not_scale_past_max_process_threshold_under_high_load() @@ -122,8 +122,8 @@ public function test_scaler_will_not_scale_past_max_process_threshold_under_high $scaler->scale($supervisor); - $this->assertEquals(10, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(10, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(10, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(10, $supervisor->processPools['second']->totalProcessCount()); } public function test_scaler_will_not_scale_below_minimum_worker_threshold() @@ -139,13 +139,13 @@ public function test_scaler_will_not_scale_below_minimum_worker_threshold() $scaler->scale($supervisor); - $this->assertEquals(3, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(2, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(3, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(2, $supervisor->processPools['second']->totalProcessCount()); $scaler->scale($supervisor); - $this->assertEquals(3, $supervisor->processPools['first']->totalProcessCount()); - $this->assertEquals(2, $supervisor->processPools['second']->totalProcessCount()); + $this->assertSame(3, $supervisor->processPools['first']->totalProcessCount()); + $this->assertSame(2, $supervisor->processPools['second']->totalProcessCount()); } protected function with_scaling_scenario($maxProcesses, array $pools, array $extraOptions = []) diff --git a/tests/Feature/FailedJobTest.php b/tests/Feature/FailedJobTest.php index 2d6771d4..68c948db 100644 --- a/tests/Feature/FailedJobTest.php +++ b/tests/Feature/FailedJobTest.php @@ -14,7 +14,7 @@ public function test_failed_jobs_are_placed_in_the_failed_job_table() { $id = Queue::push(new Jobs\FailingJob); $this->work(); - $this->assertEquals(1, $this->failedJobs()); + $this->assertSame(1, $this->failedJobs()); $this->assertGreaterThan(0, Redis::connection('horizon')->ttl($id)); $job = resolve(JobRepository::class)->getJobs([$id])[0]; @@ -22,8 +22,8 @@ public function test_failed_jobs_are_placed_in_the_failed_job_table() $this->assertTrue(isset($job->exception)); $this->assertTrue(isset($job->failed_at)); $this->assertSame('failed', $job->status); - $this->assertTrue(is_numeric($job->failed_at)); - $this->assertEquals(Jobs\FailingJob::class, $job->name); + $this->assertIsNumeric($job->failed_at); + $this->assertSame(Jobs\FailingJob::class, $job->name); } public function test_tags_for_failed_jobs_are_stored_in_redis() diff --git a/tests/Feature/JobRetrievalTest.php b/tests/Feature/JobRetrievalTest.php index 34f90cd4..e2c83729 100644 --- a/tests/Feature/JobRetrievalTest.php +++ b/tests/Feature/JobRetrievalTest.php @@ -28,18 +28,18 @@ public function test_pending_jobs_can_be_retrieved() // Test getting all jobs... $this->assertCount(5, $recent); $this->assertEquals($ids[4], $recent->first()->id); - $this->assertEquals(Jobs\BasicJob::class, $recent->first()->name); - $this->assertEquals(0, $recent->first()->index); + $this->assertSame(Jobs\BasicJob::class, $recent->first()->name); + $this->assertSame(0, $recent->first()->index); $this->assertEquals($ids[0], $recent->last()->id); - $this->assertEquals(4, $recent->last()->index); + $this->assertSame(4, $recent->last()->index); // Test pagination... $recent = $repository->getRecent(1); $this->assertCount(3, $recent); $this->assertEquals($ids[2], $recent->first()->id); - $this->assertEquals(2, $recent->first()->index); + $this->assertSame(2, $recent->first()->index); $this->assertEquals($ids[0], $recent->last()->id); - $this->assertEquals(4, $recent->last()->index); + $this->assertSame(4, $recent->last()->index); // Test no results... $recent = $repository->getRecent(4); @@ -59,10 +59,10 @@ public function test_recent_jobs_are_correctly_trimmed_and_expired() $repository = resolve(JobRepository::class); Chronos::setTestNow(Chronos::now()->addHours(3)); - $this->assertEquals(5, Redis::connection('horizon')->zcard('recent_jobs')); + $this->assertSame(5, Redis::connection('horizon')->zcard('recent_jobs')); $repository->trimRecentJobs(); - $this->assertEquals(0, Redis::connection('horizon')->zcard('recent_jobs')); + $this->assertSame(0, Redis::connection('horizon')->zcard('recent_jobs')); // Assert job record has a TTL... $repository->completed(new JobPayload(json_encode(['id' => $ids[0]]))); diff --git a/tests/Feature/MasterSupervisorTest.php b/tests/Feature/MasterSupervisorTest.php index 55454d04..ed5ca7e7 100644 --- a/tests/Feature/MasterSupervisorTest.php +++ b/tests/Feature/MasterSupervisorTest.php @@ -93,7 +93,7 @@ public function test_master_process_restarts_unexpected_exits() $command = (object) json_decode($commands[0], true); $this->assertCount(0, $master->supervisors); - $this->assertEquals(AddSupervisor::class, $command->command); + $this->assertSame(AddSupervisor::class, $command->command); $this->assertSame('default', $command->options['queue']); } @@ -148,7 +148,7 @@ public function test_master_process_loop_processes_pending_commands() $command = resolve(Commands\FakeMasterCommand::class); - $this->assertEquals(1, $command->processCount); + $this->assertSame(1, $command->processCount); $this->assertEquals($master, $command->master); $this->assertEquals(['foo' => 'bar'], $command->options); } diff --git a/tests/Feature/MetricsTest.php b/tests/Feature/MetricsTest.php index d8ad290c..06d91830 100644 --- a/tests/Feature/MetricsTest.php +++ b/tests/Feature/MetricsTest.php @@ -19,7 +19,7 @@ public function test_total_throughput_is_stored() $this->work(); $this->work(); - $this->assertEquals(2, resolve(MetricsRepository::class)->throughput()); + $this->assertSame(2, resolve(MetricsRepository::class)->throughput()); } public function test_throughput_is_stored_per_job_class() @@ -34,9 +34,9 @@ public function test_throughput_is_stored_per_job_class() $this->work(); $this->work(); - $this->assertEquals(4, resolve(MetricsRepository::class)->throughput()); - $this->assertEquals(3, resolve(MetricsRepository::class)->throughputForJob(Jobs\BasicJob::class)); - $this->assertEquals(1, resolve(MetricsRepository::class)->throughputForJob(Jobs\ConditionallyFailingJob::class)); + $this->assertSame(4, resolve(MetricsRepository::class)->throughput()); + $this->assertSame(3, resolve(MetricsRepository::class)->throughputForJob(Jobs\BasicJob::class)); + $this->assertSame(1, resolve(MetricsRepository::class)->throughputForJob(Jobs\ConditionallyFailingJob::class)); } public function test_throughput_is_stored_per_queue() @@ -51,8 +51,8 @@ public function test_throughput_is_stored_per_queue() $this->work(); $this->work(); - $this->assertEquals(4, resolve(MetricsRepository::class)->throughput()); - $this->assertEquals(4, resolve(MetricsRepository::class)->throughputForQueue('default')); + $this->assertSame(4, resolve(MetricsRepository::class)->throughput()); + $this->assertSame(4, resolve(MetricsRepository::class)->throughputForQueue('default')); } public function test_average_runtime_is_stored_per_job_class_in_milliseconds() @@ -68,7 +68,7 @@ public function test_average_runtime_is_stored_per_job_class_in_milliseconds() $this->work(); $this->work(); - $this->assertEquals(1.5, resolve(MetricsRepository::class)->runtimeForJob(Jobs\BasicJob::class)); + $this->assertSame(1.5, resolve(MetricsRepository::class)->runtimeForJob(Jobs\BasicJob::class)); } public function test_average_runtime_is_stored_per_queue_in_milliseconds() @@ -84,7 +84,7 @@ public function test_average_runtime_is_stored_per_queue_in_milliseconds() $this->work(); $this->work(); - $this->assertEquals(1.5, resolve(MetricsRepository::class)->runtimeForQueue('default')); + $this->assertSame(1.5, resolve(MetricsRepository::class)->runtimeForQueue('default')); } public function test_list_of_all_jobs_with_metric_information_is_maintained() @@ -97,8 +97,8 @@ public function test_list_of_all_jobs_with_metric_information_is_maintained() $jobs = resolve(MetricsRepository::class)->measuredJobs(); $this->assertCount(2, $jobs); - $this->assertTrue(in_array(Jobs\ConditionallyFailingJob::class, $jobs)); - $this->assertTrue(in_array(Jobs\BasicJob::class, $jobs)); + $this->assertContains(Jobs\ConditionallyFailingJob::class, $jobs); + $this->assertContains(Jobs\BasicJob::class, $jobs); } public function test_snapshot_of_metrics_performance_can_be_stored() @@ -173,22 +173,22 @@ public function test_jobs_processed_per_minute_since_last_snapshot_is_calculable $this->work(); $this->work(); - $this->assertEquals( - 2, resolve(MetricsRepository::class)->jobsProcessedPerMinute() + $this->assertSame( + 2.0, resolve(MetricsRepository::class)->jobsProcessedPerMinute() ); // Adjust current time... Chronos::setTestNow(Chronos::now()->addMinutes(2)); - $this->assertEquals( - 1, resolve(MetricsRepository::class)->jobsProcessedPerMinute() + $this->assertSame( + 1.0, resolve(MetricsRepository::class)->jobsProcessedPerMinute() ); // take snapshot and ensure count is reset... resolve(MetricsRepository::class)->snapshot(); - $this->assertEquals( - 0, resolve(MetricsRepository::class)->jobsProcessedPerMinute() + $this->assertSame( + 0.0, resolve(MetricsRepository::class)->jobsProcessedPerMinute() ); } @@ -212,12 +212,12 @@ public function test_only_past_24_snapshots_are_retained() // Check the job snapshots... $snapshots = resolve(MetricsRepository::class)->snapshotsForJob(Jobs\BasicJob::class); $this->assertCount(24, $snapshots); - $this->assertEquals(Chronos::now()->getTimestamp() - 1, $snapshots[23]->time); + $this->assertSame(Chronos::now()->getTimestamp() - 1, $snapshots[23]->time); // Check the queue snapshots... $snapshots = resolve(MetricsRepository::class)->snapshotsForQueue('default'); $this->assertCount(24, $snapshots); - $this->assertEquals(Chronos::now()->getTimestamp() - 1, $snapshots[23]->time); + $this->assertSame(Chronos::now()->getTimestamp() - 1, $snapshots[23]->time); Chronos::setTestNow(); } diff --git a/tests/Feature/MonitoringTest.php b/tests/Feature/MonitoringTest.php index 4b4603cf..d34b6d71 100644 --- a/tests/Feature/MonitoringTest.php +++ b/tests/Feature/MonitoringTest.php @@ -20,8 +20,8 @@ public function test_can_retrieve_all_monitored_tags() dispatch(new MonitorTag('second')); $monitored = $repository->monitoring(); - $this->assertTrue(in_array('first', $monitored)); - $this->assertTrue(in_array('second', $monitored)); + $this->assertContains('first', $monitored); + $this->assertContains('second', $monitored); $this->assertCount(2, $monitored); } @@ -52,7 +52,7 @@ public function test_completed_jobs_are_stored_in_database_when_one_of_their_tag dispatch(new MonitorTag('first')); $id = Queue::push(new Jobs\BasicJob); $this->work(); - $this->assertEquals(1, $this->monitoredJobs('first')); + $this->assertSame(1, $this->monitoredJobs('first')); $this->assertGreaterThan(0, Redis::connection('horizon')->ttl($id)); } @@ -62,7 +62,7 @@ public function test_completed_jobs_are_removed_from_database_when_their_tag_is_ Queue::push(new Jobs\BasicJob); $this->work(); dispatch(new StopMonitoringTag('first')); - $this->assertEquals(0, $this->monitoredJobs('first')); + $this->assertSame(0, $this->monitoredJobs('first')); } public function test_all_completed_jobs_are_removed_from_database_when_their_tag_is_no_longer_monitored() @@ -76,6 +76,6 @@ public function test_all_completed_jobs_are_removed_from_database_when_their_tag $this->work(); dispatch(new StopMonitoringTag('first')); - $this->assertEquals(0, $this->monitoredJobs('first')); + $this->assertSame(0, $this->monitoredJobs('first')); } } diff --git a/tests/Feature/ProvisioningPlanTest.php b/tests/Feature/ProvisioningPlanTest.php index 0fed4c33..10b68eed 100644 --- a/tests/Feature/ProvisioningPlanTest.php +++ b/tests/Feature/ProvisioningPlanTest.php @@ -31,9 +31,9 @@ public function test_supervisors_are_added() $this->assertCount(1, $commands); $command = (object) json_decode($commands[0], true); - $this->assertEquals(AddSupervisor::class, $command->command); + $this->assertSame(AddSupervisor::class, $command->command); $this->assertSame('first', $command->options['queue']); - $this->assertEquals(20, $command->options['maxProcesses']); + $this->assertSame(20, $command->options['maxProcesses']); } public function test_supervisors_are_added_by_wildcard() @@ -57,9 +57,9 @@ public function test_supervisors_are_added_by_wildcard() $this->assertCount(1, $commands); $command = (object) json_decode($commands[0], true); - $this->assertEquals(AddSupervisor::class, $command->command); + $this->assertSame(AddSupervisor::class, $command->command); $this->assertSame('first', $command->options['queue']); - $this->assertEquals(20, $command->options['maxProcesses']); + $this->assertSame(20, $command->options['maxProcesses']); } public function test_plan_is_converted_into_array_of_supervisor_options() @@ -90,12 +90,12 @@ public function test_plan_is_converted_into_array_of_supervisor_options() $results = (new ProvisioningPlan(MasterSupervisor::name(), $plan))->toSupervisorOptions(); - $this->assertEquals(MasterSupervisor::name().':supervisor-1', $results['production']['supervisor-1']->name); + $this->assertSame(MasterSupervisor::name().':supervisor-1', $results['production']['supervisor-1']->name); $this->assertSame('redis', $results['production']['supervisor-1']->connection); $this->assertSame('default', $results['production']['supervisor-1']->queue); $this->assertTrue($results['production']['supervisor-1']->balance); $this->assertTrue($results['production']['supervisor-1']->autoScale); - $this->assertEquals(20, $results['local']['supervisor-2']->maxProcesses); + $this->assertSame(20, $results['local']['supervisor-2']->maxProcesses); } } diff --git a/tests/Feature/QueueProcessingTest.php b/tests/Feature/QueueProcessingTest.php index 2ef9de6a..5690a309 100644 --- a/tests/Feature/QueueProcessingTest.php +++ b/tests/Feature/QueueProcessingTest.php @@ -23,21 +23,21 @@ public function test_completed_jobs_are_not_normally_stored_in_completed_databas { Queue::push(new Jobs\BasicJob); $this->work(); - $this->assertEquals(0, $this->monitoredJobs('first')); - $this->assertEquals(0, $this->monitoredJobs('second')); + $this->assertSame(0, $this->monitoredJobs('first')); + $this->assertSame(0, $this->monitoredJobs('second')); } public function test_pending_jobs_are_stored_in_pending_job_database() { $id = Queue::push(new Jobs\BasicJob); - $this->assertEquals(1, $this->recentJobs()); + $this->assertSame(1, $this->recentJobs()); $this->assertSame('pending', Redis::connection('horizon')->hget($id, 'status')); } public function test_pending_delayed_jobs_are_stored_in_pending_job_database() { $id = Queue::later(1, new Jobs\BasicJob); - $this->assertEquals(1, $this->recentJobs()); + $this->assertSame(1, $this->recentJobs()); $this->assertSame('pending', Redis::connection('horizon')->hget($id, 'status')); } diff --git a/tests/Feature/RedisJobRepositoryTest.php b/tests/Feature/RedisJobRepositoryTest.php index be673ad3..6f240a9e 100644 --- a/tests/Feature/RedisJobRepositoryTest.php +++ b/tests/Feature/RedisJobRepositoryTest.php @@ -17,7 +17,7 @@ public function test_it_can_find_a_failed_job_by_its_id() $repository->failed(new Exception('Failed Job'), 'redis', 'default', $payload); - $this->assertEquals(1, $repository->findFailed(1)->id); + $this->assertSame('1', $repository->findFailed(1)->id); } public function test_it_will_not_find_a_failed_job_if_the_job_has_not_failed() diff --git a/tests/Feature/RedisPrefixTest.php b/tests/Feature/RedisPrefixTest.php index 0370deb0..54d53543 100644 --- a/tests/Feature/RedisPrefixTest.php +++ b/tests/Feature/RedisPrefixTest.php @@ -14,6 +14,6 @@ public function test_prefix_can_be_configured() Horizon::use('default'); - $this->assertEquals('custom:', config('database.redis.horizon.options.prefix')); + $this->assertSame('custom:', config('database.redis.horizon.options.prefix')); } } diff --git a/tests/Feature/RetryJobTest.php b/tests/Feature/RetryJobTest.php index 83d29aa9..e85cbcc8 100644 --- a/tests/Feature/RetryJobTest.php +++ b/tests/Feature/RetryJobTest.php @@ -34,7 +34,7 @@ public function test_failed_job_can_be_retried_successfully_with_a_fresh_id() $_SERVER['horizon.fail'] = true; $id = Queue::push(new Jobs\ConditionallyFailingJob); $this->work(); - $this->assertEquals(1, $this->failedJobs()); + $this->assertSame(1, $this->failedJobs()); // Monitor the tag so the job is stored in the completed table... dispatch(new MonitorTag('first')); @@ -50,8 +50,8 @@ public function test_failed_job_can_be_retried_successfully_with_a_fresh_id() // Work the now-passing job... $this->work(); - $this->assertEquals(1, $this->failedJobs()); - $this->assertEquals(1, $this->monitoredJobs('first')); + $this->assertSame(1, $this->failedJobs()); + $this->assertSame(1, $this->monitoredJobs('first')); // Test that retry job ID reference is stored on original failed job... $retried = Redis::connection('horizon')->hget($id, 'retried_by'); diff --git a/tests/Feature/SupervisorCommandTest.php b/tests/Feature/SupervisorCommandTest.php index 230f2a0e..4ac48510 100644 --- a/tests/Feature/SupervisorCommandTest.php +++ b/tests/Feature/SupervisorCommandTest.php @@ -34,7 +34,7 @@ public function test_supervisor_command_can_set_process_niceness() $this->app->instance(SupervisorFactory::class, $factory = new FakeSupervisorFactory); $this->artisan('horizon:supervisor', ['name' => 'foo', 'connection' => 'redis', '--nice' => 10]); - $this->assertEquals(10, $this->myNiceness()); + $this->assertSame(10, $this->myNiceness()); } private function myNiceness() diff --git a/tests/Feature/SupervisorTest.php b/tests/Feature/SupervisorTest.php index bcb1d2a3..ea8dccc2 100644 --- a/tests/Feature/SupervisorTest.php +++ b/tests/Feature/SupervisorTest.php @@ -52,7 +52,7 @@ protected function tearDown(): void public function test_supervisor_can_start_worker_process_with_given_options() { Queue::push(new Jobs\BasicJob); - $this->assertEquals(1, $this->recentJobs()); + $this->assertSame(1, $this->recentJobs()); $this->supervisor = $supervisor = new Supervisor($this->supervisorOptions()); @@ -66,7 +66,7 @@ public function test_supervisor_can_start_worker_process_with_given_options() $this->assertCount(1, $supervisor->processes()); $host = MasterSupervisor::name(); - $this->assertEquals( + $this->assertSame( 'exec '.$this->phpBinary.' worker.php redis --delay=0 --memory=128 --queue="default" --sleep=3 --timeout=60 --tries=0 --supervisor='.$host.':name', $supervisor->processes()[0]->getCommandLine() ); @@ -84,12 +84,12 @@ public function test_supervisor_starts_multiple_pools_when_balancing() $host = MasterSupervisor::name(); - $this->assertEquals( + $this->assertSame( 'exec '.$this->phpBinary.' worker.php redis --delay=0 --memory=128 --queue="first" --sleep=3 --timeout=60 --tries=0 --supervisor='.$host.':name', $supervisor->processes()[0]->getCommandLine() ); - $this->assertEquals( + $this->assertSame( 'exec '.$this->phpBinary.' worker.php redis --delay=0 --memory=128 --queue="second" --sleep=3 --timeout=60 --tries=0 --supervisor='.$host.':name', $supervisor->processes()[1]->getCommandLine() ); @@ -98,7 +98,7 @@ public function test_supervisor_starts_multiple_pools_when_balancing() public function test_recent_jobs_are_correctly_maintained() { $id = Queue::push(new Jobs\BasicJob); - $this->assertEquals(1, $this->recentJobs()); + $this->assertSame(1, $this->recentJobs()); $this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions()); @@ -106,7 +106,7 @@ public function test_recent_jobs_are_correctly_maintained() $supervisor->loop(); $this->wait(function () { - $this->assertEquals(1, $this->recentJobs()); + $this->assertSame(1, $this->recentJobs()); }); $this->wait(function () use ($id) { @@ -163,8 +163,8 @@ public function test_supervisor_information_is_persisted() $record = resolve(SupervisorRepository::class)->find($supervisor->name); $this->assertSame('running', $record->status); - $this->assertEquals(2, collect($record->processes)->sum()); - $this->assertEquals(2, $record->processes['redis:default,another']); + $this->assertSame(2, collect($record->processes)->sum()); + $this->assertSame(2, $record->processes['redis:default,another']); $this->assertTrue(isset($record->pid)); $this->assertSame('redis', $record->options['connection']); @@ -253,7 +253,7 @@ public function test_processes_can_be_paused_and_continued() Queue::push(new Jobs\BasicJob); usleep(1100 * 1000); - $this->assertEquals(1, $this->recentJobs()); + $this->assertSame(1, $this->recentJobs()); $supervisor->continue(); $this->assertTrue($supervisor->processPools[0]->working); @@ -312,7 +312,7 @@ public function test_supervisor_can_prune_terminating_processes_and_return_total $supervisor->scale(0); usleep(500 * 1000); - $this->assertEquals(0, $supervisor->pruneAndGetTotalProcesses()); + $this->assertSame(0, $supervisor->pruneAndGetTotalProcesses()); } public function test_terminating_processes_that_are_stuck_are_hard_stopped() @@ -370,7 +370,7 @@ public function test_supervisor_loop_processes_pending_supervisor_commands() $command = resolve(Commands\FakeCommand::class); - $this->assertEquals(1, $command->processCount); + $this->assertSame(1, $command->processCount); $this->assertEquals($supervisor, $command->supervisor); $this->assertEquals(['foo' => 'bar'], $command->options); } @@ -392,12 +392,12 @@ public function test_supervisor_should_start_paused_workers_when_paused_and_scal $supervisor->loop(); - $this->assertEquals(2, $supervisor->totalProcessCount()); + $this->assertSame(2, $supervisor->totalProcessCount()); Queue::push(new Jobs\BasicJob); usleep(500 * 1000); - $this->assertEquals(1, $this->recentJobs()); + $this->assertSame(1, $this->recentJobs()); } public function test_auto_scaler_is_called_on_loop_when_auto_scaling() @@ -442,7 +442,7 @@ public function test_supervisor_processes_can_be_counted_externally() $supervisor->loop(); $this->wait(function () use ($supervisor) { - $this->assertEquals(3, $supervisor->totalSystemProcessCount()); + $this->assertSame(3, $supervisor->totalSystemProcessCount()); }); } @@ -454,21 +454,21 @@ public function test_supervisor_does_not_start_workers_until_looped_and_active() $supervisor->scale(3); $this->wait(function () use ($supervisor) { - $this->assertEquals(0, $supervisor->totalSystemProcessCount()); + $this->assertSame(0, $supervisor->totalSystemProcessCount()); }); $supervisor->working = false; $supervisor->loop(); $this->wait(function () use ($supervisor) { - $this->assertEquals(0, $supervisor->totalSystemProcessCount()); + $this->assertSame(0, $supervisor->totalSystemProcessCount()); }); $supervisor->working = true; $supervisor->loop(); $this->wait(function () use ($supervisor) { - $this->assertEquals(3, $supervisor->totalSystemProcessCount()); + $this->assertSame(3, $supervisor->totalSystemProcessCount()); }); } diff --git a/tests/Feature/TagRepositoryTest.php b/tests/Feature/TagRepositoryTest.php index cab7933f..4ef12f4a 100644 --- a/tests/Feature/TagRepositoryTest.php +++ b/tests/Feature/TagRepositoryTest.php @@ -18,13 +18,13 @@ public function test_pagination_of_job_ids_can_be_accomplished() $results = $repo->paginate('tag', 0, 25); $this->assertCount(25, $results); - $this->assertEquals(49, $results[0]); - $this->assertEquals(25, $results[24]); + $this->assertSame('49', $results[0]); + $this->assertSame('25', $results[24]); $results = $repo->paginate('tag', last(array_keys($results)) + 1, 25); $this->assertCount(25, $results); - $this->assertEquals(24, $results[25]); - $this->assertEquals(0, $results[49]); + $this->assertSame('24', $results[25]); + $this->assertSame('0', $results[49]); } } diff --git a/tests/Feature/WaitTimeCalculatorTest.php b/tests/Feature/WaitTimeCalculatorTest.php index 1f0920fd..477ffc99 100644 --- a/tests/Feature/WaitTimeCalculatorTest.php +++ b/tests/Feature/WaitTimeCalculatorTest.php @@ -101,8 +101,8 @@ public function test_single_queue_can_be_retrieved_for_multiple_queues() $calculator->calculate('redis:test-queue-2') ); - $this->assertEquals( - 40, + $this->assertSame( + 40.0, $calculator->calculateFor('redis:test-queue-2') ); }