only retry r.ReqlTimeoutError because creating a database with too many replicas or shards raises a r.ReqlAvailabilityError, which resulted in an infinite loop; add test for this case

This commit is contained in:
Noah Levitt 2015-09-22 21:34:12 +00:00
parent 030d248eac
commit a377fd5305
2 changed files with 11 additions and 4 deletions

View File

@ -21,7 +21,7 @@ class RethinkerWrapper:
conn = self.rethinker._random_server_connection()
is_iter = False
try:
result = self.wrapped.run(conn, db=db or self.rethinker.db)
result = self.wrapped.run(conn, db=db or self.rethinker.dbname)
if hasattr(result, "__next__"):
is_iter = True
def gen():
@ -41,8 +41,8 @@ class RethinkerWrapper:
return g
else:
return result
except (r.ReqlAvailabilityError, r.ReqlTimeoutError) as e:
pass
except r.ReqlTimeoutError as e:
time.sleep(0.5)
finally:
if not is_iter:
conn.close(noreply_wait=False)
@ -56,7 +56,7 @@ class Rethinker(object):
def __init__(self, servers=['localhost'], db=None):
self.servers = servers
self.db = db
self.dbname = db
# https://github.com/rethinkdb/rethinkdb-example-webpy-blog/blob/master/model.py
# "Best practices: Managing connections: a connection per request"

View File

@ -3,6 +3,8 @@ import logging
import sys
import types
import gc
import pytest
import rethinkdb
logging.basicConfig(stream=sys.stderr, level=logging.INFO,
format="%(asctime)s %(process)d %(levelname)s %(threadName)s %(name)s.%(funcName)s(%(filename)s:%(lineno)d) %(message)s")
@ -64,3 +66,8 @@ def test_rethinker():
# connection should be closed after result is garbage-collected
assert not r.last_conn.is_open()
with pytest.raises(rethinkdb.errors.ReqlOpFailedError):
r.table_create("too_many_replicas", replicas=99).run()
with pytest.raises(rethinkdb.errors.ReqlOpFailedError):
r.table_create("too_many_shards", shards=99).run()