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:
parent
9daa2abcb7
commit
aac0f945c9
1 changed files with 34 additions and 0 deletions
34
test/thread_safe_test.rb
Normal file
34
test/thread_safe_test.rb
Normal 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
|
Loading…
Reference in a new issue