10
10
describe "threadhot" do
11
11
12
12
before :each do
13
+ ActiveRecord ::Base . connection . reconnect!
13
14
TagHierarchy . delete_all
14
15
Tag . delete_all
15
16
@iterations = 5
16
17
@workers = 6 # Travis CI workers can't reliably handle larger numbers
17
18
@parent = nil
19
+ @time_between_runs = 1
18
20
end
19
21
20
22
def find_or_create_at_even_second ( run_at )
21
23
sleep ( run_at - Time . now . to_f )
22
24
ActiveRecord ::Base . connection . reconnect!
23
- ( @parent || Tag ) . find_or_create_by_path ( [ run_at . to_s , :a , :b , :c ] . compact )
25
+ ( @parent || Tag ) . find_or_create_by_path ( [ run_at . to_s , :a , :b , :c ] )
24
26
end
25
27
26
28
def run_workers
27
- start_time = Time . now . to_i + 2
28
- @times = @iterations . times . collect { |ea | start_time + ( ea * 2 ) }
29
+ expected_thread_setup_time = 4
30
+ start_time = Time . now . to_i + expected_thread_setup_time
31
+ @times = @iterations . times . collect { |ea | start_time + ( ea * @time_between_runs ) }
29
32
@names = @times . collect { |ea | ea . to_s }
30
33
@threads = @workers . times . collect do
31
34
Thread . new do
@@ -78,12 +81,10 @@ def run_workers
78
81
target . find_or_create_by_path ( name )
79
82
children_to_delete << name
80
83
added_children << name
81
- puts "+ #{ name } "
82
84
end
83
85
end while !children_to_add . empty?
84
86
end
85
87
end
86
- sleep 0.5
87
88
run_destruction = true
88
89
destroyer_threads = @workers . times . map do
89
90
Thread . new do
@@ -93,9 +94,8 @@ def run_workers
93
94
if victim
94
95
target . children . where ( :name => victim ) . first . destroy
95
96
deleted_children << victim
96
- puts "- #{ victim } "
97
97
else
98
- sleep 0.1
98
+ sleep rand # wait for moar victims
99
99
end
100
100
end while run_destruction || !children_to_delete . empty?
101
101
end
0 commit comments