Skip to content

Commit

Permalink
Add a test for abruptly closed connections
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Jun 30, 2022
1 parent 79d4d89 commit eb7023e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/redis_client/connection_test.rb
Expand Up @@ -192,6 +192,23 @@ def test_reconnect_with_call_once
assert_equal "1", client.call("GET", "counter")
end

def test_killed_connection
client = new_client(reconnect_attempts: 1, id: "background")

thread = Thread.new do
client.blocking_call(false, "BLPOP", "list", 0)
end
thread.join(0.1)
assert_predicate thread, :alive?

second_client = new_client

id = second_client.call("CLIENT", "LIST").lines.grep(/name=background/)[0].match(/^id=(\d+)/)[1]
assert_equal 1, second_client.call("CLIENT", "KILL", "ID", id)
second_client.call("LPUSH", "list", "hello")
assert_equal ["list", "hello"], thread.join.value
end

private

def assert_timeout(error, faster_than = 0.5, &block)
Expand Down

0 comments on commit eb7023e

Please sign in to comment.