spec/integration/fork_reconnect_spec.rb in mongo-2.14.0.rc1 vs spec/integration/fork_reconnect_spec.rb in mongo-2.14.0
- old
+ new
@@ -1,10 +1,10 @@
require 'spec_helper'
describe 'fork reconnect' do
require_fork
- only_mri
+ require_mri
# On multi-shard sharded clusters a succeeding write request does not
# guarantee that the next operation will succeed (since it could be sent to
# another shard with a dead connection).
require_no_multi_shard
@@ -136,8 +136,63 @@
end
# Perform a read which can be retried, so that the socket close
# performed by the child is recovered from.
client['foo'].find(test: 1)
+ end
+
+ # Test from Driver Sessions Spec
+ # * Create ClientSession
+ # * Record its lsid
+ # * Delete it (so the lsid is pushed into the pool)
+ # * Fork
+ # * In the parent, create a ClientSession and assert its lsid is the same.
+ # * In the child, create a ClientSession and assert its lsid is different.
+ describe 'session pool' do
+ it 'is cleared after fork' do
+ session = client.get_session
+ parent_lsid = session.session_id
+ session.end_session
+ if pid = fork
+ pid, status = Process.wait2(pid)
+ status.exitstatus.should == 0
+ else
+ Utils.wrap_forked_child do
+ client.reconnect
+ child_session = client.get_session
+ child_lsid = child_session.session_id
+ expect(child_lsid).not_to eq(parent_lsid)
+ end
+ end
+
+ expect(client.get_session.session_id).to eq(parent_lsid)
+ end
+
+ # Test from Driver Sessions Spec
+ # * Create ClientSession
+ # * Record its lsid
+ # * Fork
+ # * In the parent, return the ClientSession to the pool, create a new ClientSession, and assert its lsid is the same.
+ # * In the child, return the ClientSession to the pool, create a new ClientSession, and assert its lsid is different.
+ it 'does not return parent process sessions to child process pool' do
+ session = client.get_session
+ parent_lsid = session.session_id
+
+ if pid = fork
+ pid, status = Process.wait2(pid)
+ status.exitstatus.should == 0
+ else
+ Utils.wrap_forked_child do
+ client.reconnect
+ session.end_session
+ child_session = client.get_session
+ child_lsid = child_session.session_id
+ expect(child_lsid).not_to eq(parent_lsid)
+ end
+ end
+
+ session.end_session
+ expect(client.get_session.session_id).to eq(parent_lsid)
+ end
end
end
end