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

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