From aad1e3329d8e13d23ce8fe9a2b63547006140aa4 Mon Sep 17 00:00:00 2001 From: Jedrzej Nowak Date: Thu, 10 Dec 2015 11:25:28 +0100 Subject: [PATCH 1/2] Fixed gevent related test failures --- solar/dblayer/model.py | 35 +++++++++++++++++++++-------------- solar/dblayer/solar_models.py | 10 +++++----- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/solar/dblayer/model.py b/solar/dblayer/model.py index 1750b440..2436b88e 100644 --- a/solar/dblayer/model.py +++ b/solar/dblayer/model.py @@ -181,16 +181,17 @@ def requires_clean_state(_type): def check_state_for(_type, obj): - state = obj._c.db_ch_state.get(_type) - if state: - if True: - # TODO: solve it - obj.save_all_lazy() - state = obj._c.db_ch_state.get(_type) - if not state: - return - raise Exception("Dirty state, save all %r objects first" % - obj.__class__) + with obj._lock: + state = obj._c.db_ch_state.get(_type) + if state: + if True: + # TODO: solve it + obj.save_all_lazy() + state = obj._c.db_ch_state.get(_type) + if not state: + return + raise Exception("Dirty state, save all %r objects first" % + obj.__class__) @total_ordering @@ -731,6 +732,8 @@ class Model(object): _local = get_local()() + _lock = RLock() # for class objs + def __init__(self, key=None): self._modified_fields = set() # TODO: that _indexes_changed should be smarter @@ -853,9 +856,13 @@ class Model(object): raise DBLayerException("Object already exists in cache" " cannot create second") data['key'] = key - riak_obj = cls.bucket.new(key, data={}) - obj = cls.from_riakobj(riak_obj) - obj._new = True + + with cls._c.obj_cache._lock: + 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: # if field is cls._pkey_field: @@ -901,7 +908,7 @@ class Model(object): to_save.save() except DBLayerException: continue - cls._c.lazy_save.clear() + cls._c.lazy_save.clear() @clears_state_for('index') def save(self, force=False): diff --git a/solar/dblayer/solar_models.py b/solar/dblayer/solar_models.py index f8166ce3..3d6436b2 100644 --- a/solar/dblayer/solar_models.py +++ b/solar/dblayer/solar_models.py @@ -392,12 +392,12 @@ class InputsFieldWrp(IndexFieldWrp): return self._cache[full_name] except KeyError: 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: + 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), endkey='{}|~'.format(my_name), return_terms=True) From f4da9eb8e1dd6f98c746fa00fcf7a516e2d81a4b Mon Sep 17 00:00:00 2001 From: Jedrzej Nowak Date: Thu, 10 Dec 2015 16:45:51 +0100 Subject: [PATCH 2/2] Added gevent to test-requirements --- test-requirements.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test-requirements.txt b/test-requirements.txt index 500eec70..6b4e5084 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -9,3 +9,6 @@ os-testr # for computable inputs lupa + +# to test if everything works on gevent +gevent