Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
Ugly specs and a first-request bug fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Mitchell committed Mar 8, 2011
1 parent dce68c5 commit 1c4286c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/kestrel/client.rb
Expand Up @@ -147,7 +147,9 @@ def extract_kestrel_options!(opts)
end

def shuffle_if_necessary!(key)
if key != @current_queue || @counter >= @gets_per_server
# Don't reset servers on the first request:
# i.e. @counter == 0 && @current_queue == nil
if (@counter > 0 && key != @current_queue) || @counter >= @gets_per_server
@counter = 0
@current_queue = key
@read_client.quit
Expand Down
14 changes: 9 additions & 5 deletions spec/kestrel/client_spec.rb
Expand Up @@ -18,17 +18,21 @@
end

it "gets from the same server :gets_per_server times" do
mock(@kestrel).get_from_last("a_queue/t=10", false).times(100) { 'item' }
mock(@kestrel).get_from_random("a_queue/t=10", false).times(2) { 'item' }
client = @kestrel.instance_variable_get(:@read_client)
mock(client).get_from_last("a_queue/t=10", true).times(102).returns('item')
mock(client).quit.once
mock(client).set_servers.with(anything).once

102.times { @kestrel.get("a_queue") }
end

it "gets from a different server when the last result was nil" do
mock(@kestrel).get_from_last("a_queue/t=10", false).never { nil }
mock(@kestrel).get_from_random("a_queue/t=10", false).times(3) { nil }
client = @kestrel.instance_variable_get(:@read_client)
mock(client).get_from_last("a_queue/t=10", true).returns(nil).twice
mock(client).quit.once
mock(client).set_servers.with(anything).once

3.times { @kestrel.get("a_queue") }
2.times { @kestrel.get("a_queue") }
end

it "returns nil if there is a recoverable exception" do
Expand Down

0 comments on commit 1c4286c

Please sign in to comment.