From 92f671958dfc2ebd882961b85faaeb5ab14376e0 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Mon, 23 Feb 2009 15:37:53 -0500 Subject: [PATCH] add simple auto-reconnect test script --- tools/auto_reconnect_test.py | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tools/auto_reconnect_test.py diff --git a/tools/auto_reconnect_test.py b/tools/auto_reconnect_test.py new file mode 100644 index 000000000..15c2b6e16 --- /dev/null +++ b/tools/auto_reconnect_test.py @@ -0,0 +1,43 @@ +# Copyright 2009 10gen, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Simple script to help test auto-reconnection.""" + +import threading +import time + +from pymongo.errors import ConnectionFailure +from pymongo.connection import Connection + +db = Connection.paired(("localhost", 27018), pool_size=10).test +db.test.remove({}) + +class Something(threading.Thread): + def run(self): + while True: + time.sleep(1) + try: + id = db.test.save({"x": 1}) + assert db.test.find_one(id)["x"] == 1 + db.test.remove(id) + db.connection().end_request() + print "Y" + except ConnectionFailure, e: + print e + print "N" + +for _ in range(1): + t = Something() + t.start() + time.sleep(1)