Skip to content

Commit

Permalink
Merge pull request #421 from pigmej/fix-gevent-errors
Browse files Browse the repository at this point in the history
Fixed gevent related test failures
  • Loading branch information
loles committed Dec 10, 2015
2 parents bfec251 + f4da9eb commit 501a189
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
35 changes: 21 additions & 14 deletions solar/dblayer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,17 @@ def _inner2(obj, *args, **kwargs):


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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -853,9 +856,13 @@ def from_dict(cls, key, data=None):
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:
Expand Down Expand Up @@ -901,7 +908,7 @@ def save_all_lazy(cls):
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):
Expand Down
10 changes: 5 additions & 5 deletions solar/dblayer/solar_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,12 @@ def _get_field_val(self, name, other=None):
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)
Expand Down
3 changes: 3 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ os-testr

# for computable inputs
lupa

# to test if everything works on gevent
gevent

0 comments on commit 501a189

Please sign in to comment.