-
Notifications
You must be signed in to change notification settings - Fork 111
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
1 parent
8be436d
commit a41d711
Showing
1 changed file
with
31 additions
and
4 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 |
---|---|---|
@@ -1,8 +1,35 @@ | ||
import threading | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
import aerospike | ||
|
||
def test_unsafe(): | ||
n_threads = 10 | ||
barrier = threading.Barrier(n_threads) | ||
|
||
def test_unsafe(as_connection): | ||
key = ("test", "demo", 1) | ||
BIN_VALUE = 1 | ||
as_connection.put(key, policy={"a": BIN_VALUE}) | ||
|
||
bin_value_sum = 0 | ||
|
||
THREAD_COUNT = 10 | ||
barrier = threading.Barrier(parties=THREAD_COUNT) | ||
config = {"hosts": [("127.0.0.1", 3000)]} | ||
|
||
def read_bin(): | ||
barrier.wait() | ||
client = aerospike.client(config) | ||
_, _, bins = client.get(key) | ||
nonlocal bin_value_sum | ||
bin_value_sum += bins["a"] | ||
|
||
workers = [] | ||
for _ in range(THREAD_COUNT): | ||
workers.append(threading.Thread(target=read_bin)) | ||
|
||
for worker in workers: | ||
worker.start() | ||
|
||
for worker in workers: | ||
worker.join() | ||
|
||
# Do something about the results | ||
assert bin_value_sum == THREAD_COUNT * BIN_VALUE |