Project

General

Profile

Actions

Patch #41931

closed

Fix random failures in IssueRelationTest#test_create_with_initialized_journals due to ambiguous conditions for retrieving the expected detail

Added by Katsuya HIDAKA 16 days ago. Updated 11 days ago.

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

0%

Estimated time:

Description

The IssueRelationTest#test_create_with_initialized_journals test fails randomly with the following error:

Failure:  
IssueRelationTest#test_create_with_initialized_journals_should_create_journals [test/unit/issue_relation_test.rb:220]:  
Expected: "relation"  
  Actual: "attr"  

bin/rails test test/unit/issue_relation_test.rb:202  

The exact reason for the random failures is unclear, but it is likely related to the order of details in to.journals.last.details.

Currently, to.journals.last.details contains three Detail entries in the following order:

  1. property: 'relation', prop_key: 'follows' (expected value)
  2. property: 'attr', prop_key: 'due_date'
  3. property: 'attr', prop_key: 'start_date' (actual value)

As a result, to.journals.last.details.last does not match the expected Detail in the test.

This behavior appears to be correct. When an IssueRelation with a "precedes" type is created, the handle_issue_order callback updates the due_date and start_date of the related issue. These updates are recorded in the journal, resulting in additional Detail entries.

I have attached the patch for updating the test to verify the presence of the expected Detail without relying on the order. Additionally, the patch includes assertions to ensure that to.journals.last.details contains changes to due_date and start_date.

diff --git a/test/unit/issue_relation_test.rb b/test/unit/issue_relation_test.rb
index a223fe42c..198dd94ad 100644
--- a/test/unit/issue_relation_test.rb
+++ b/test/unit/issue_relation_test.rb
@@ -202,25 +202,27 @@ class IssueRelationTest < ActiveSupport::TestCase
   def test_create_with_initialized_journals_should_create_journals
     from = Issue.find(1)
     to   = Issue.find(2)
-    from_journals = from.journals.size
-    to_journals   = to.journals.size
     relation = IssueRelation.new(:issue_from => from, :issue_to => to,
                                  :relation_type => IssueRelation::TYPE_PRECEDES)
     relation.init_journals User.find(1)
-    assert relation.save
-    from.reload
-    to.reload
-    relation.reload
-    assert_equal from.journals.size, (from_journals + 1)
-    assert_equal to.journals.size, (to_journals + 1)
-    assert_equal 'relation', from.journals.last.details.last.property
-    assert_equal 'precedes', from.journals.last.details.last.prop_key
-    assert_equal '2', from.journals.last.details.last.value
-    assert_nil   from.journals.last.details.last.old_value
-    assert_equal 'relation', to.journals.last.details.last.property
-    assert_equal 'follows', to.journals.last.details.last.prop_key
-    assert_equal '1', to.journals.last.details.last.value
-    assert_nil   to.journals.last.details.last.old_value
+
+    assert_difference(
+      ->{ from.reload.journals.size } => +1,
+      ->{ to.reload.journals.size } => +1
+    ) do
+      assert relation.save
+    end
+
+    from.journals.last.details.then do |details|
+      assert details.exists?(property: 'relation', prop_key: 'precedes', value: '2')
+    end
+
+    to.journals.last.details.then do |details|
+      assert_equal 3, details.count
+      assert details.exists?(property: 'relation', prop_key: 'follows', value: '1', old_value: nil)
+      assert details.exists?(property: 'attr', prop_key: 'due_date')
+      assert details.exists?(property: 'attr', prop_key: 'start_date')
+    end
   end

   def test_destroy_with_initialized_journals_should_create_journals

Files

Actions #2

Updated by Go MAEDA 16 days ago

  • Target version set to 5.1.5
Actions #3

Updated by Go MAEDA 16 days ago

  • Status changed from New to Resolved
  • Assignee set to Go MAEDA

Committed the fix in r23350. Thank you.

Actions #4

Updated by Go MAEDA 11 days ago

  • Status changed from Resolved to Closed

Merged the fix into the stable branches in r23355 and r23356.

Actions

Also available in: Atom PDF