Project

General

Profile

Actions

Patch #41901

closed

Fix random test failure in DestroyProjectsJobTest due to unsorted @projects

Added by Katsuya HIDAKA 27 days ago. Updated 26 days ago.

Status:
Closed
Priority:
Normal
Category:
Code cleanup/refactoring
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

The test "schedule should enqueue job" fails randomly because @projects is not sorted. The query Project.where(id: [1, 2]) does not ensure a consistent order, which causes occasional mismatches in the test's args assertion.

Failure:
DestroyProjectsJobTest#test_schedule_should_enqueue_job [test/unit/jobs/destroy_projects_job_test.rb:41]:
No enqueued job found with {:job=>DestroyProjectsJob, :args=>[[1, 2], 1, "127.0.0.1"]}

Potential matches: {"job_class"=>"DestroyProjectsJob", (snip) "arguments"=>[[2, 1], 1, "127.0.0.1"], "executions"=>0, "exception_executions"=>{}, "locale"=>"en", "timezone"=>"UTC", "enqueued_at"=>"2024-11-17T05:32:51.712506223Z", "scheduled_at"=>nil, :job=>DestroyProjectsJob, :args=>[[2, 1], 1, "127.0.0.1"], :queue=>"default", :priority=>nil}

bin/rails test test/unit/jobs/destroy_projects_job_test.rb:42

Adding .order(:id) fixes the issue by ensuring consistent ordering of @projects.

diff --git a/test/unit/jobs/destroy_projects_job_test.rb b/test/unit/jobs/destroy_projects_job_test.rb
index ed06f0896..01a83fc03 100644
--- a/test/unit/jobs/destroy_projects_job_test.rb
+++ b/test/unit/jobs/destroy_projects_job_test.rb
@@ -23,7 +23,7 @@ class DestroyProjectsJobTest < ActiveJob::TestCase
   fixtures :users, :projects, :email_addresses

   setup do
-    @projects = Project.where(id: [1, 2]).to_a
+    @projects = Project.where(id: [1, 2]).order(:id).to_a
     @user = User.find_by_admin true
     ActionMailer::Base.deliveries.clear
   end

Files

Actions

Also available in: Atom PDF