Skip to content

Commit

Permalink
Add a test for threading (#21)
Browse files Browse the repository at this point in the history
Something in python 3.12.2 seems to have changed the threading
behaviour, which causes odd results.
  • Loading branch information
Jamstah authored Apr 24, 2024
1 parent f2ec771 commit 94435d0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/test_minidb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import concurrent.futures
import minidb
import pytest
import datetime
Expand Down Expand Up @@ -662,3 +663,29 @@ class Thing(minidb.Model):

db.delete_all(Thing)
assert db.count_rows(Thing) == 0

def test_threaded_query():
class Thing(minidb.Model):
s = str
i = int

with minidb.Store(debug=True, vacuum_on_close=False) as db:
db.register(Thing)

for i in range(100):
db.save(Thing(s=str(i), i=i))

def query(i):
things = list(Thing.query(db, Thing.c.s // Thing.c.i, where=Thing.c.i==i))
assert len(things) == 1

thing = things[0]
assert thing is not None
assert thing.s == str(i)
assert thing.i == i

return i

executor = concurrent.futures.ThreadPoolExecutor(max_workers=10)
# Wrap in list to resolve all the futures
list(executor.map(query, range(100)))

0 comments on commit 94435d0

Please sign in to comment.