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()
|
conn = self.rethinker._random_server_connection()
|
||||||
is_iter = False
|
is_iter = False
|
||||||
try:
|
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__"):
|
if hasattr(result, "__next__"):
|
||||||
is_iter = True
|
is_iter = True
|
||||||
def gen():
|
def gen():
|
||||||
@ -41,8 +41,8 @@ class RethinkerWrapper:
|
|||||||
return g
|
return g
|
||||||
else:
|
else:
|
||||||
return result
|
return result
|
||||||
except (r.ReqlAvailabilityError, r.ReqlTimeoutError) as e:
|
except r.ReqlTimeoutError as e:
|
||||||
pass
|
time.sleep(0.5)
|
||||||
finally:
|
finally:
|
||||||
if not is_iter:
|
if not is_iter:
|
||||||
conn.close(noreply_wait=False)
|
conn.close(noreply_wait=False)
|
||||||
@ -56,7 +56,7 @@ class Rethinker(object):
|
|||||||
|
|
||||||
def __init__(self, servers=['localhost'], db=None):
|
def __init__(self, servers=['localhost'], db=None):
|
||||||
self.servers = servers
|
self.servers = servers
|
||||||
self.db = db
|
self.dbname = db
|
||||||
|
|
||||||
# https://github.com/rethinkdb/rethinkdb-example-webpy-blog/blob/master/model.py
|
# https://github.com/rethinkdb/rethinkdb-example-webpy-blog/blob/master/model.py
|
||||||
# "Best practices: Managing connections: a connection per request"
|
# "Best practices: Managing connections: a connection per request"
|
||||||
|
@ -3,6 +3,8 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
import gc
|
import gc
|
||||||
|
import pytest
|
||||||
|
import rethinkdb
|
||||||
|
|
||||||
logging.basicConfig(stream=sys.stderr, level=logging.INFO,
|
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")
|
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
|
# connection should be closed after result is garbage-collected
|
||||||
assert not r.last_conn.is_open()
|
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