Sha256: 6f9ec228552bfb6a423dd16f9e93f42cae48a069342b1d46a6a302ce8609f994
Contents?: true
Size: 956 Bytes
Versions: 1
Compression:
Stored size: 956 Bytes
Contents
require 'minitest/unit' require 'minitest/autorun' require "sdb_lock" class LockTest < MiniTest::Unit::TestCase def setup @lock = SdbLock.new( 'lock_test', create_domain: true, simple_db_endpoint: "sdb.ap-northeast-1.amazonaws.com" ) @lock.unlock("test") end # This test will take long time (16 secs in my environment). def test_try_lock shared_var = 0 locked_count = 0 threads = 10.times.map do Thread.new do Thread.pass locked = @lock.try_lock("test") { shared_var += 1 } locked_count += 1 if locked end end threads.each { |thread| thread.join } assert_equal(locked_count, shared_var) end def test_lock shared_var = 0 threads = 10.times.map do Thread.new do Thread.pass @lock.lock("test") { shared_var += 1 } end end threads.each { |thread| thread.join } assert_equal(10, shared_var) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sdb_lock-0.0.2 | test/lock_test.rb |