2010-03-19 14:19:01 +00:00
|
|
|
require 'test_helper'
|
2010-03-04 00:45:33 +00:00
|
|
|
|
2011-02-08 17:16:35 +00:00
|
|
|
class ThreadSafetyTest < ActionController::TestCase
|
2010-03-19 14:19:01 +00:00
|
|
|
should "be thread safe" do
|
2010-03-04 00:45:33 +00:00
|
|
|
blocked = true
|
2010-03-19 14:19:01 +00:00
|
|
|
|
|
|
|
slow_thread = Thread.new do
|
2010-03-04 00:45:33 +00:00
|
|
|
controller = TestController.new
|
2010-03-19 14:19:01 +00:00
|
|
|
controller.send :set_whodunnit
|
2010-03-04 00:45:33 +00:00
|
|
|
begin
|
2010-03-19 14:19:01 +00:00
|
|
|
sleep 0.001
|
2010-03-04 00:45:33 +00:00
|
|
|
end while blocked
|
|
|
|
PaperTrail.whodunnit
|
|
|
|
end
|
|
|
|
|
2010-03-19 14:19:01 +00:00
|
|
|
fast_thread = Thread.new do
|
2010-03-04 00:45:33 +00:00
|
|
|
controller = TestController.new
|
2010-03-19 14:19:01 +00:00
|
|
|
controller.send :set_whodunnit
|
|
|
|
who = PaperTrail.whodunnit
|
2010-03-04 00:45:33 +00:00
|
|
|
blocked = false
|
2010-03-19 14:19:01 +00:00
|
|
|
who
|
2010-03-04 00:45:33 +00:00
|
|
|
end
|
2010-03-19 14:19:01 +00:00
|
|
|
|
|
|
|
assert_not_equal slow_thread.value, fast_thread.value
|
2010-03-04 00:45:33 +00:00
|
|
|
end
|
2010-03-19 14:19:01 +00:00
|
|
|
end
|