diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2023-11-19 11:02:24 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2023-11-19 11:02:24 +0000 |
commit | 4daed3c8678d2afce69cbd626d309b6ce3cfc913 (patch) | |
tree | 690c8be1648d457b6cf5f684ea08bb0fd19569ea /test | |
parent | 85f5cbc77880dff69fc12716b8157fb0bdaaa664 (diff) | |
download | redmine-4daed3c8678d2afce69cbd626d309b6ce3cfc913.tar.gz redmine-4daed3c8678d2afce69cbd626d309b6ce3cfc913.zip |
Merged r22458, r22459, r22460, r22461, r22462 and r22464 from trunk to 5.1-stable (#39437).
git-svn-id: https://svn.redmine.org/redmine/branches/5.1-stable@22467 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r-- | test/test_helper.rb | 4 | ||||
-rw-r--r-- | test/unit/issue_nested_set_concurrency_test.rb | 50 |
2 files changed, 53 insertions, 1 deletions
diff --git a/test/test_helper.rb b/test/test_helper.rb index c5fe079c8..19fa1ca4f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -203,6 +203,10 @@ class ActiveSupport::TestCase Redmine::Database.mysql? end + def mysql8? + Gem::Version.new(Redmine::Database.mysql_version) >= Gem::Version.new('8.0.0') + end + def postgresql? Redmine::Database.postgresql? end diff --git a/test/unit/issue_nested_set_concurrency_test.rb b/test/unit/issue_nested_set_concurrency_test.rb index 9400b62cc..7f45a4b8d 100644 --- a/test/unit/issue_nested_set_concurrency_test.rb +++ b/test/unit/issue_nested_set_concurrency_test.rb @@ -29,7 +29,12 @@ class IssueNestedSetConcurrencyTest < ActiveSupport::TestCase self.use_transactional_tests = false def setup - skip if sqlite? || mysql? + skip if sqlite? + if mysql? + connection = ActiveRecord::Base.connection_db_config.configuration_hash.deep_dup + connection[:variables] = mysql8? ? { transaction_isolation: "READ-COMMITTED" } : { tx_isolation: "READ-COMMITTED" } + ActiveRecord::Base.establish_connection connection + end User.current = nil CustomField.delete_all end @@ -74,6 +79,49 @@ class IssueNestedSetConcurrencyTest < ActiveSupport::TestCase assert_equal (2..61).to_a, children_bounds end + def test_concurrent_subtask_removal + with_settings :notified_events => [] do + root = Issue.generate! + 60.times do + Issue.generate! :parent_issue_id => root.id + end + # pick 40 random subtask ids + child_ids = Issue.where(root_id: root.id, parent_id: root.id).pluck(:id) + ids_to_remove = child_ids.sample(40).shuffle + ids_to_keep = child_ids - ids_to_remove + # remove these from the set, using four parallel threads + threads = [] + ids_to_remove.each_slice(10) do |ids| + threads << Thread.new do + ActiveRecord::Base.connection_pool.with_connection do + begin + ids.each do |id| + Issue.find(id).update(parent_id: nil) + end + rescue => e + Thread.current[:exception] = e.message + end + end + end + end + threads.each do |thread| + thread.join + assert_nil thread[:exception] + end + assert_equal 20, Issue.where(parent_id: root.id).count + Issue.where(id: ids_to_remove).each do |issue| + assert_nil issue.parent_id + assert_equal issue.id, issue.root_id + assert_equal 1, issue.lft + assert_equal 2, issue.rgt + end + root.reload + assert_equal [1, 42], [root.lft, root.rgt] + children_bounds = root.children.sort_by(&:lft).map {|c| [c.lft, c.rgt]}.flatten + assert_equal (2..41).to_a, children_bounds + end + end + private def threaded(count, &block) |