Skip to content
Snippets Groups Projects
Commit b51dfac2 authored by ale's avatar ale
Browse files

add load test to highlight concurrency issues

parent 7ccfa20a
No related branches found
No related tags found
No related merge requests found
...@@ -73,6 +73,30 @@ class DatabaseTest(TestBase): ...@@ -73,6 +73,30 @@ class DatabaseTest(TestBase):
self.db.set(w) self.db.set(w)
self.assertTrue(self.db.are_we_done()) self.assertTrue(self.db.are_we_done())
def test_loadtest(self):
nkeys = 100
nloops = 100
out = {'errors': 0}
for i in xrange(nkeys):
self.db.put(state.WorkUnit('key%d' % i, state.STATE_INIT, {i: i}))
self.db.conn.commit()
def loadfn(i):
key = 'key%d' % i
for j in xrange(nloops):
try:
with state.work_transaction(self.db, key) as work:
work.state = state.STATE_DONE
except Exception, e:
out['errors'] += 1
print e
threads = [threading.Thread(target=loadfn, args=(i,)) for i in xrange(nkeys)]
[x.start() for x in threads]
[x.join() for x in threads]
self.assertEquals(0, out['errors'])
def _mk_state_machine(_states): def _mk_state_machine(_states):
class _MySM(state.StateMachine): class _MySM(state.StateMachine):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment