paper-trail-gem--paper_trail/test/functional/thread_safety_test.rb

27 lines
572 B
Ruby
Raw Normal View History

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