@@ -27,6 +27,7 class IssueNestedSetConcurrencyTest < ActiveSupport::TestCase | |||
|
27 | 27 | self.use_transactional_fixtures = false |
|
28 | 28 | |
|
29 | 29 | def setup |
|
30 | skip if sqlite? | |
|
30 | 31 | CustomField.delete_all |
|
31 | 32 | end |
|
32 | 33 | |
@@ -35,38 +36,60 class IssueNestedSetConcurrencyTest < ActiveSupport::TestCase | |||
|
35 | 36 | end |
|
36 | 37 | |
|
37 | 38 | def test_concurrency |
|
38 | skip if sqlite? | |
|
39 | with_settings :notified_events => [] do | |
|
40 | # Generates an issue and destroys it in order | |
|
41 | # to load all needed classes before starting threads | |
|
42 | i = Issue.generate! | |
|
43 | i.destroy | |
|
39 | # Generates an issue and destroys it in order | |
|
40 | # to load all needed classes before starting threads | |
|
41 | i = Issue.generate! | |
|
42 | i.destroy | |
|
44 | 43 | |
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 | threads << Thread.new(i) do | |
|
50 | ActiveRecord::Base.connection_pool.with_connection do | |
|
51 | begin | |
|
52 | 10.times do | |
|
53 | i = Issue.generate! :parent_issue_id => root.id | |
|
54 | c1 = Issue.generate! :parent_issue_id => i.id | |
|
55 | c2 = Issue.generate! :parent_issue_id => i.id | |
|
56 | c3 = Issue.generate! :parent_issue_id => i.id | |
|
57 | c2.reload.destroy | |
|
58 | c1.reload.destroy | |
|
59 | end | |
|
60 | rescue Exception => e | |
|
61 | Thread.current[:exception] = e.message | |
|
62 | end | |
|
44 | root = Issue.generate! | |
|
45 | assert_difference 'Issue.count', 60 do | |
|
46 | threaded(3) do | |
|
47 | 10.times do | |
|
48 | i = Issue.generate! :parent_issue_id => root.id | |
|
49 | c1 = Issue.generate! :parent_issue_id => i.id | |
|
50 | c2 = Issue.generate! :parent_issue_id => i.id | |
|
51 | c3 = Issue.generate! :parent_issue_id => i.id | |
|
52 | c2.reload.destroy | |
|
53 | c1.reload.destroy | |
|
54 | end | |
|
55 | end | |
|
56 | end | |
|
57 | end | |
|
58 | ||
|
59 | def test_concurrent_subtasks_creation | |
|
60 | root = Issue.generate! | |
|
61 | assert_difference 'Issue.count', 30 do | |
|
62 | threaded(3) do | |
|
63 | 10.times do | |
|
64 | Issue.generate! :parent_issue_id => root.id | |
|
65 | end | |
|
66 | end | |
|
67 | end | |
|
68 | root.reload | |
|
69 | assert_equal [1, 62], [root.lft, root.rgt] | |
|
70 | children_bounds = root.children.sort_by(&:lft).map {|c| [c.lft, c.rgt]}.flatten | |
|
71 | assert_equal (2..61).to_a, children_bounds | |
|
72 | end | |
|
73 | ||
|
74 | private | |
|
75 | ||
|
76 | def threaded(count, &block) | |
|
77 | with_settings :notified_events => [] do | |
|
78 | threads = [] | |
|
79 | count.times do |i| | |
|
80 | threads << Thread.new(i) do | |
|
81 | ActiveRecord::Base.connection_pool.with_connection do | |
|
82 | begin | |
|
83 | yield | |
|
84 | rescue Exception => e | |
|
85 | Thread.current[:exception] = e.message | |
|
63 | 86 | end |
|
64 | 87 | end |
|
65 | 88 | end |
|
66 | threads.each do |thread| | |
|
67 | thread.join | |
|
68 | assert_nil thread[:exception] | |
|
69 | end | |
|
89 | end | |
|
90 | threads.each do |thread| | |
|
91 | thread.join | |
|
92 | assert_nil thread[:exception] | |
|
70 | 93 | end |
|
71 | 94 | end |
|
72 | 95 | end |
General Comments 0
You need to be logged in to leave comments.
Login now