Skip to content

Commit

Permalink
Minor fixes to pool reuse tests (refactor, cleanup used connections)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheald committed Dec 29, 2012
1 parent 057b799 commit c8ce44d
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions test/auxillary/pool_reuse_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ def count_open_file_handles
@conn["admin"].command(:serverStatus => 1)["connections"]["current"]
end

def setup
ensure_cluster(:rs, :replicas => 2, :arbiters => 1)
connect
end

def teardown
@@cluster.stop if @@cluster
@conn.close if @conn
end

def test_pool_resources_are_reused
ensure_cluster(:rs)
def connect
@conn.close if @conn
@conn = MongoReplicaSetClient.new(["%s:%s" % [@rs.primary.host, @rs.primary.port]])
end

def test_pool_resources_are_reused
handles_before_refresh = count_open_file_handles
10.times do
@conn.hard_refresh!
Expand All @@ -24,12 +32,12 @@ def test_pool_resources_are_reused
end

def test_pool_connectability_after_cycling_members
ensure_cluster(:rs, :replicas => 2, :arbiters => 1)
conn = MongoReplicaSetClient.new(["%s:%s" % [@rs.primary.host, @rs.primary.port]])
db = conn['sample-db']
db = @conn['sample-db']

assert_equal db.collection_names, []
@@cluster.primary.stop
old_primary = @@cluster.primary
@conn["admin"].command step_down_command rescue nil
old_primary.stop

rescue_connection_failure do
db.collection_names
Expand All @@ -39,10 +47,12 @@ def test_pool_connectability_after_cycling_members
assert_equal db.collection_names, []

# Start up the old primary
@@cluster.restart
old_primary.start

# Stop the new primary
@@cluster.primary.stop
primary = @@cluster.primary
@conn["admin"].command step_down_command rescue nil
primary.stop

# Wait for primary failover
rescue_connection_failure do
Expand Down

0 comments on commit c8ce44d

Please sign in to comment.