mirror of
https://github.com/internetarchive/warcprox.git
synced 2025-01-18 13:22:09 +01:00
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:
parent
030d248eac
commit
a377fd5305
@ -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"
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user