Sha256: 6e33ee2b7b81b8cce1bbcca5313ed73a743bea8d82ea22886079374495e06454

Contents?: true

Size: 907 Bytes

Versions: 15

Compression:

Stored size: 907 Bytes

Contents

require_relative "helper"

class Post < Ohm::Model; end
class Role < Ohm::Model; end

class User < Ohm::Model
  list :posts, :Post
  set  :roles, :Role
end

setup do
  User.create
end

test "list#replace" do |user|
  Post.mutex.lock

  thread = Thread.new { user.posts.replace([Post.create]) }

  sleep 0.1

  assert_equal true, thread.alive?

  Post.mutex.unlock

  sleep 0.1

  assert_equal false, thread.alive?

  thread.join
end

test "set#replace" do |user|
  Role.mutex.lock

  thread = Thread.new { user.roles.replace([Role.create]) }

  sleep 0.1

  assert_equal true, thread.alive?

  Role.mutex.unlock

  sleep 0.1

  assert_equal false, thread.alive?

  thread.join
end

test "collection#fetch" do
  User.mutex.lock

  thread = Thread.new { User.all.to_a }

  sleep 0.1

  assert_equal true, thread.alive?

  User.mutex.unlock

  sleep 0.1

  assert_equal false, thread.alive?

  thread.join
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
ohm_util-0.1 test/thread_safety.rb
ohm-3.1.1 test/thread_safety.rb
ohm-3.1.0 test/thread_safety.rb
ohm-3.0.3 test/thread_safety.rb
ohm-3.0.2 test/thread_safety.rb
ohm-3.0.1 test/thread_safety.rb
ohm-3.0.0 test/thread_safety.rb
ohm-2.3.0 test/thread_safety.rb
ohm-2.2.1 test/thread_safety.rb
sohm-0.0.1 test/thread_safety.rb
ohm-2.2.0 test/thread_safety.rb
ohm-2.1.0 test/thread_safety.rb
ohm-2.0.1 test/thread_safety.rb
ohm-2.0.0 test/thread_safety.rb
ohm-2.0.0.rc2 test/thread_safety.rb