test/client_test.rb in suo-0.2.0 vs test/client_test.rb in suo-0.2.1

- old
+ new

@@ -8,11 +8,11 @@ client = @client.class.new(client: {}) client.lock(TEST_KEY, 1) end end - def test_class_single_resource_locking + def test_single_resource_locking lock1 = @client.lock(TEST_KEY, 1) refute_nil lock1 locked = @client.locked?(TEST_KEY, 1) assert_equal true, locked @@ -25,11 +25,11 @@ locked = @client.locked?(TEST_KEY, 1) assert_equal false, locked end - def test_class_multiple_resource_locking + def test_multiple_resource_locking lock1 = @client.lock(TEST_KEY, 2) refute_nil lock1 locked = @client.locked?(TEST_KEY, 2) assert_equal false, locked @@ -70,12 +70,13 @@ def test_readme_example output = Queue.new threads = [] - threads << Thread.new { @client.lock(TEST_KEY, 2) { output << "One"; sleep 2 } } - threads << Thread.new { @client.lock(TEST_KEY, 2) { output << "Two"; sleep 2 } } + threads << Thread.new { @client.lock(TEST_KEY, 2) { output << "One"; sleep 0.5 } } + threads << Thread.new { @client.lock(TEST_KEY, 2) { output << "Two"; sleep 0.5 } } + sleep 0.1 threads << Thread.new { @client.lock(TEST_KEY, 2) { output << "Three" } } threads.map(&:join) ret = [] @@ -84,22 +85,22 @@ ret << output.pop ret.sort! assert_equal 0, output.size - assert_equal ["One", "Two"], ret + assert_equal %w(One Two), ret end - def test_instance_multiple_resource_locking + def test_block_multiple_resource_locking success_counter = Queue.new failure_counter = Queue.new client = @client.class.new(acquisition_timeout: 0.9, client: @client.client) 100.times.map do |i| Thread.new do - success = @client.lock(TEST_KEY, 50) do + success = client.lock(TEST_KEY, 50) do sleep(3) success_counter << i end failure_counter << i unless success @@ -108,10 +109,10 @@ assert_equal 50, success_counter.size assert_equal 50, failure_counter.size end - def test_instance_multiple_resource_locking_longer_timeout + def test_block_multiple_resource_locking_longer_timeout success_counter = Queue.new failure_counter = Queue.new client = @client.class.new(acquisition_timeout: 3, client: @client.client)