test/multithreaded_test.rb in radius-ts-1.1.0 vs test/multithreaded_test.rb in radius-ts-1.3.0

- old
+ new

@@ -10,20 +10,51 @@ "#{tag.locals.thread_id} / #{tag.globals.object_id}" end end end - def test_runs_multithreaded - threads = [] - 1000.times do |t| - threads << Thread.new do - parser = Radius::Parser.new(@context, :tag_prefix => 'r') - parser.context.globals.thread_id = Thread.current.object_id - expected = "#{Thread.current.object_id} / #{parser.context.globals.object_id}" - actual = parser.parse('<r:thread />') - assert_equal expected, actual + if RUBY_PLATFORM == 'java' + require 'java' + def test_runs_multithreaded + lock = java.lang.String.new("lock") + threads = [] + 1000.times do |t| + thread = Thread.new do + parser = Radius::Parser.new(@context, :tag_prefix => 'r') + parser.context.globals.thread_id = Thread.current.object_id + expected = "#{Thread.current.object_id} / "+ + "#{parser.context.globals.object_id}" + actual = parser.parse('<r:thread />') + assert_equal expected, actual + end + lock.synchronized do + threads << thread + end end + lock.synchronized do + threads.each{|t| t.join } + end end - threads.each{|t| t.join } + else + def test_runs_multithreaded + threads = [] + mute = Mutex.new + 1000.times do |t| + thread = Thread.new do + parser = Radius::Parser.new(@context, :tag_prefix => 'r') + parser.context.globals.thread_id = Thread.current.object_id + expected = "#{Thread.current.object_id} / "+ + "#{parser.context.globals.object_id}" + actual = parser.parse('<r:thread />') + assert_equal expected, actual + end + mute.synchronize do + threads << thread + end + end + mute.synchronize do + threads.each{|t| t.join } + end + end end end