1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00

Added a test for Thread safety

This commit is contained in:
Phan Le 2010-03-04 11:45:33 +11:00 committed by Andy Stewart
parent 9daa2abcb7
commit aac0f945c9

34
test/thread_safe_test.rb Normal file
View file

@ -0,0 +1,34 @@
require File.dirname(__FILE__) + '/test_helper.rb'
class TestController < ActionController::Base
def current_user
@current_user ||= ActiveSupport::SecureRandom.hex(32)
end
end
class ThreadSafeTest < Test::Unit::TestCase
should "is thread safe when dealing with audit logging" do
blocked = true
blocked_thread = Thread.new do
controller = TestController.new
controller.send(:set_whodunnit)
begin
puts "sleep for .001 sec"
sleep(0.001)
end while blocked
PaperTrail.whodunnit
end
fast_running_thread = Thread.new do
controller = TestController.new
controller.send(:set_whodunnit)
blocked = false
PaperTrail.whodunnit
end
assert_not_equal blocked_thread.value, fast_running_thread.value
end
end