Merge pull request #421 from pigmej/fix-gevent-errors

Fixed gevent related test failures
This commit is contained in:
Łukasz Oleś 2015-12-10 16:51:14 +01:00
commit 501a1899e3
3 changed files with 29 additions and 19 deletions

View File

@ -181,16 +181,17 @@ def requires_clean_state(_type):
def check_state_for(_type, obj): def check_state_for(_type, obj):
state = obj._c.db_ch_state.get(_type) with obj._lock:
if state: state = obj._c.db_ch_state.get(_type)
if True: if state:
# TODO: solve it if True:
obj.save_all_lazy() # TODO: solve it
state = obj._c.db_ch_state.get(_type) obj.save_all_lazy()
if not state: state = obj._c.db_ch_state.get(_type)
return if not state:
raise Exception("Dirty state, save all %r objects first" % return
obj.__class__) raise Exception("Dirty state, save all %r objects first" %
obj.__class__)
@total_ordering @total_ordering
@ -731,6 +732,8 @@ class Model(object):
_local = get_local()() _local = get_local()()
_lock = RLock() # for class objs
def __init__(self, key=None): def __init__(self, key=None):
self._modified_fields = set() self._modified_fields = set()
# TODO: that _indexes_changed should be smarter # TODO: that _indexes_changed should be smarter
@ -853,9 +856,13 @@ class Model(object):
raise DBLayerException("Object already exists in cache" raise DBLayerException("Object already exists in cache"
" cannot create second") " cannot create second")
data['key'] = key data['key'] = key
riak_obj = cls.bucket.new(key, data={})
obj = cls.from_riakobj(riak_obj) with cls._c.obj_cache._lock:
obj._new = True if key in cls._c.obj_cache:
return cls._c.obj_cache.get(key)
riak_obj = cls.bucket.new(key, data={})
obj = cls.from_riakobj(riak_obj)
obj._new = True
for field in cls._model_fields: for field in cls._model_fields:
# if field is cls._pkey_field: # if field is cls._pkey_field:
@ -901,7 +908,7 @@ class Model(object):
to_save.save() to_save.save()
except DBLayerException: except DBLayerException:
continue continue
cls._c.lazy_save.clear() cls._c.lazy_save.clear()
@clears_state_for('index') @clears_state_for('index')
def save(self, force=False): def save(self, force=False):

View File

@ -398,12 +398,12 @@ class InputsFieldWrp(IndexFieldWrp):
return self._cache[full_name] return self._cache[full_name]
except KeyError: except KeyError:
pass pass
check_state_for('index', self._instance)
fname = self.fname
my_name = self._instance.key
self._has_own_input(name)
ind_name = '{}_recv_bin'.format(fname)
with self.inputs_index_cache as c: with self.inputs_index_cache as c:
check_state_for('index', self._instance)
fname = self.fname
my_name = self._instance.key
self._has_own_input(name)
ind_name = '{}_recv_bin'.format(fname)
kwargs = dict(startkey='{}|'.format(my_name), kwargs = dict(startkey='{}|'.format(my_name),
endkey='{}|~'.format(my_name), endkey='{}|~'.format(my_name),
return_terms=True) return_terms=True)

View File

@ -9,3 +9,6 @@ os-testr
# for computable inputs # for computable inputs
lupa lupa
# to test if everything works on gevent
gevent