test/client_test.rb in suo-0.1.2 vs test/client_test.rb in suo-0.1.3
- old
+ new
@@ -9,10 +9,16 @@
end
assert_equal "Client required", exception.message
end
+ def test_throws_failed_error_on_bad_client
+ assert_raises(Suo::LockClientError) do
+ @klass.lock(TEST_KEY, 1, client: {})
+ end
+ end
+
def test_class_single_resource_locking
lock1 = @klass.lock(TEST_KEY, 1, client: @klass_client)
refute_nil lock1
locked = @klass.locked?(TEST_KEY, 1, client: @klass_client)
@@ -71,40 +77,40 @@
def test_instance_multiple_resource_locking
success_counter = Queue.new
failure_counter = Queue.new
- 100.times.map do |i|
+ 50.times.map do |i|
Thread.new do
- success = @client.lock(TEST_KEY, 50, retry_timeout: 0.5) do
- sleep(2)
+ success = @client.lock(TEST_KEY, 25, retry_timeout: 0.9) do
+ sleep(3)
success_counter << i
end
failure_counter << i unless success
end
end.map(&:join)
- assert_equal 50, success_counter.size
- assert_equal 50, failure_counter.size
+ assert_equal 25, success_counter.size
+ assert_equal 25, failure_counter.size
end
def test_instance_multiple_resource_locking_longer_timeout
success_counter = Queue.new
failure_counter = Queue.new
- 100.times.map do |i|
+ 50.times.map do |i|
Thread.new do
- success = @client.lock(TEST_KEY, 50, retry_timeout: 2) do
+ success = @client.lock(TEST_KEY, 25, retry_timeout: 2) do
sleep(0.5)
success_counter << i
end
failure_counter << i unless success
end
end.map(&:join)
- assert_equal 100, success_counter.size
+ assert_equal 50, success_counter.size
assert_equal 0, failure_counter.size
end
end
class TestBaseClient < Minitest::Test