You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

project_nested_set_concurrency_test.rb 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class ProjectNestedSetConcurrencyTest < ActiveSupport::TestCase
  20. self.use_transactional_tests = false
  21. def setup
  22. User.current = nil
  23. CustomField.delete_all
  24. end
  25. def teardown
  26. Project.delete_all
  27. end
  28. def test_concurrency
  29. skip if sqlite?
  30. # Generates a project and destroys it in order
  31. # to load all needed classes before starting threads
  32. p = generate_project!
  33. p.destroy
  34. assert_difference 'Project.async_count.value', 60 do
  35. threads = []
  36. 3.times do |i|
  37. threads << Thread.new(i) do
  38. ActiveRecord::Base.connection_pool.with_connection do
  39. begin
  40. 10.times do
  41. p = generate_project!
  42. c1 = generate_project! :parent_id => p.id
  43. c2 = generate_project! :parent_id => p.id
  44. c3 = generate_project! :parent_id => p.id
  45. c2.reload.destroy
  46. c1.reload.destroy
  47. end
  48. rescue => e
  49. Thread.current[:exception] = e.message
  50. end
  51. end
  52. end
  53. end
  54. threads.each do |thread|
  55. thread.join
  56. assert_nil thread[:exception]
  57. end
  58. end
  59. end
  60. # Generates a bare project with random name
  61. # and identifier
  62. def generate_project!(attributes={})
  63. identifier = "a" + Redmine::Utils.random_hex(6)
  64. Project.generate!(
  65. {
  66. :identifier => identifier,
  67. :name => identifier,
  68. :tracker_ids => [],
  69. :enabled_module_names => []
  70. }.merge(attributes)
  71. )
  72. end
  73. end