-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import json | ||
import random | ||
import threading | ||
|
||
from jamesql import JameSQL | ||
from jamesql.index import GSI_INDEX_STRATEGIES | ||
|
||
|
||
def test_threading(): | ||
with open("tests/fixtures/documents.json") as f: | ||
documents = json.load(f) | ||
|
||
index = JameSQL() | ||
|
||
index.create_gsi("title", strategy=GSI_INDEX_STRATEGIES.CONTAINS) | ||
index.create_gsi("lyric", strategy=GSI_INDEX_STRATEGIES.CONTAINS) | ||
|
||
for document in documents * 100: | ||
document = document.copy() | ||
index.add(document, doc_id=str(random.randint(0, 1000000))) | ||
|
||
def query(i): | ||
if i == 0: | ||
document = documents[0].copy() | ||
document["title"] = "teal" | ||
index.add(document, "xyz") | ||
index.create_gsi("title", strategy=GSI_INDEX_STRATEGIES.CONTAINS) | ||
|
||
assert len(index.string_query_search("teal")["documents"]) == 1 | ||
|
||
threads = [] | ||
|
||
for i in range(25): | ||
t = threading.Thread(target=query, args=(i,)) | ||
threads.append(t) | ||
t.start() | ||
|
||
for t in threads: | ||
t.join() | ||
|
||
assert len(index.global_index) == 301 | ||
assert index.global_index["xyz"]["title"] == "teal" |