Skip to content

Commit

Permalink
Fixed failing timeouts in TestClient
Browse files Browse the repository at this point in the history
  • Loading branch information
jcn committed Dec 29, 2008
1 parent 6c284cf commit b96de05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/juggernaut/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def alive?
# past the timeout (if we are within the timeout, the user could
# just be doing a page reload or going to a new page)
def give_up?
@connections.empty? and (logout_timeout ? (Time.now > logout_timeout) : true)
!alive? and (logout_timeout ? (Time.now > logout_timeout) : true)
end

protected
Expand Down
20 changes: 12 additions & 8 deletions test/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,22 @@ class DummySubscriber; end
@s2.stubs(:alive?).returns(false)
assert_equal false, @client.alive?
end

should "give up if at least one subscriber is timed out" do
@s1.stubs(:logout_timeout).returns(Time.now + 5)
@s2 = DummySubscriber.new
@client.add_new_connection(@s2)
@s2.stubs(:logout_timeout).returns(Time.now - 1)
assert @client.give_up?

should "not give up if within the timeout period" do
@s1.stubs(:alive?).returns(false)
@client.stubs(:logout_timeout).returns(Time.now + 10)
assert_equal false, @client.give_up?
end

should "not give up if at least one subscriber is alive" do
@s1.stubs(:alive?).returns(true)
@client.stubs(:logout_timeout).returns(Time.now - 1)
assert_equal false, @client.give_up?
end

should "send logouts after timeout" do
@s1.stubs(:alive?).returns(false)
@s1.stubs(:logout_timeout).returns(Time.now - 1)
@client.stubs(:logout_timeout).returns(Time.now - 1)
@client.expects(:logout_request).once
Juggernaut::Client.send_logouts_after_timeout
end
Expand Down

0 comments on commit b96de05

Please sign in to comment.