Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kestrel blocking client with signal checks for the kestrel-client gem.
module Kestrel
class Client
class BlockingWithCheck < Blocking
attr_accessor :return_check
def get(*args)
count = 0
while count += 1
if response = client.get(*args)
return response
end
sleep_for_count(count)
if @return_check
return if @return_check.call
end
end
end
end
end
end
require 'spec_helper'
require 'kestrel/client/blocking_with_check'
describe Kestrel::Client::BlockingWithCheck do
let(:client) { Kestrel::Client.new }
subject {
described_class.new(client)
}
before do
client.stub(:get => nil)
end
it "blocks if return check is false" do
subject.return_check = proc { false }
client.should_receive(:get).with(:foo).exactly(3).times.and_return(nil, nil, 'woot')
Timeout.timeout(0.05) do
subject.get(:foo).should eq('woot')
end
end
it "returns if check is true" do
subject.return_check = proc { true }
Timeout.timeout(0.05) do
subject.get(:foo)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.