test/scout/test_work_queue.rb in scout-gear-8.0.0 vs test/scout/test_work_queue.rb in scout-gear-8.1.0
- old
+ new
@@ -88,63 +88,85 @@
assert_equal 0, res.length
end
def test_queue_error
- num = 100
- reps = 10_000
+ 5.times do |i|
+ num = 100
+ reps = 10_000
- q = WorkQueue.new num do |obj|
- raise ScoutException if rand < 0.1
- [Process.pid.to_s, obj.to_s] * " "
- end
+ q = WorkQueue.new num do |obj|
+ raise ScoutException if rand < 0.1
+ [Process.pid.to_s, obj.to_s] * " "
+ end
- res = []
- q.process do |out|
- res << out
- end
+ res = []
+ q.process do |out|
+ res << out
+ end
- Log.with_severity 7 do
- pid = Process.fork do
- reps.times do |i|
- q.write i
+ Log.with_severity 7 do
+ t = Thread.new do
+ Thread.current["name"] = "queue writer"
+ Thread.current.report_on_exception = false
+ reps.times do |i|
+ q.write i
+ end
+ q.close
end
- end
+ Thread.pass until t["name"]
- Process.waitpid pid
-
- assert_raise ScoutException do
- q.join
- t.join
+ assert_raise ScoutException do
+ begin
+ q.join(false)
+ rescue
+ t.raise($!)
+ raise $!
+ ensure
+ t.join
+ end
+ end
end
end
end
def test_queue_error_in_input
- num = 100
- reps = 10_000
+ 5.times do |i|
+ num = 100
+ reps = 10_000
- q = WorkQueue.new num do |obj|
- [Process.pid.to_s, obj.to_s] * " "
- end
+ q = WorkQueue.new num do |obj|
+ [Process.pid.to_s, obj.to_s] * " "
+ end
- res = []
- q.process do |out|
- raise ScoutException
- res << out
- end
+ res = []
+ q.process do |out|
+ raise ScoutException
+ res << out
+ end
- Log.with_severity 7 do
- pid = Process.fork do
- reps.times do |i|
- q.write i
+ Log.with_severity 7 do
+ t = Thread.new do
+ Thread.current.report_on_exception = false
+ Thread.current["name"] = "queue writer"
+ reps.times do |i|
+ q.write i
+ end
+ q.close
end
- q.close
- end
+ Thread.pass until t["name"]
- assert_raise ScoutException do
- q.join
- t.join
+ assert_raise ScoutException do
+ begin
+ q.join(false)
+ rescue Exception
+ t.raise($!)
+ raise $!
+ ensure
+ t.join
+ q.clean
+ end
+ end
end
end
end
end