Sha256: dfcee553b3572b978fad39ceb5c62473d79247f2275364c04e295e4568d2366e

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require "test_helper"

class ThreadSafetyTest < ActionController::TestCase
  test "thread-safe when using #set_paper_trail_whodunnit" do
    blocked = true

    slow_thread = Thread.new do
      controller = TestController.new
      controller.send :set_paper_trail_whodunnit
      sleep 0.001 while blocked
      PaperTrail.whodunnit
    end

    fast_thread = Thread.new do
      controller = TestController.new
      controller.send :set_paper_trail_whodunnit
      who = PaperTrail.whodunnit
      blocked = false
      who
    end

    assert_not_equal slow_thread.value, fast_thread.value
  end

  test "thread-safe when using #without_versioning" do
    enabled = nil

    slow_thread = Thread.new do
      Widget.new.without_versioning do
        sleep(0.01)
        enabled = Widget.paper_trail_enabled_for_model?
        sleep(0.01)
      end
      enabled
    end

    fast_thread = Thread.new do
      sleep(0.005)
      Widget.paper_trail_enabled_for_model?
    end

    assert_not_equal slow_thread.value, fast_thread.value
    assert Widget.paper_trail_enabled_for_model?
    assert PaperTrail.enabled_for_model?(Widget)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
paper_trail-5.1.1 test/functional/thread_safety_test.rb
paper_trail-5.1.0 test/functional/thread_safety_test.rb
paper_trail-5.0.1 test/functional/thread_safety_test.rb
paper_trail-5.0.0 test/functional/thread_safety_test.rb