-
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
a41d711
commit 0d89565
Showing
2 changed files
with
27 additions
and
25 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,35 +1,37 @@ | ||
import threading | ||
|
||
import pytest | ||
import aerospike | ||
|
||
|
||
def test_unsafe(as_connection): | ||
key = ("test", "demo", 1) | ||
BIN_VALUE = 1 | ||
as_connection.put(key, policy={"a": BIN_VALUE}) | ||
@pytest.mark.usefixtures("as_connection") | ||
class TestFreeThreading: | ||
def test_unsafe(self): | ||
key = ("test", "demo", 1) | ||
BIN_VALUE = 1 | ||
self.as_connection.put(key, bins={"a": BIN_VALUE}) | ||
|
||
bin_value_sum = 0 | ||
bin_value_sum = 0 | ||
|
||
THREAD_COUNT = 10 | ||
barrier = threading.Barrier(parties=THREAD_COUNT) | ||
config = {"hosts": [("127.0.0.1", 3000)]} | ||
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"] | ||
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)) | ||
workers = [] | ||
for _ in range(THREAD_COUNT): | ||
workers.append(threading.Thread(target=read_bin)) | ||
|
||
for worker in workers: | ||
worker.start() | ||
for worker in workers: | ||
worker.start() | ||
|
||
for worker in workers: | ||
worker.join() | ||
for worker in workers: | ||
worker.join() | ||
|
||
# Do something about the results | ||
assert bin_value_sum == THREAD_COUNT * BIN_VALUE | ||
# Do something about the results | ||
assert bin_value_sum == THREAD_COUNT * BIN_VALUE |
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,3 +1,3 @@ | ||
pytest==7.4.0 | ||
pytest==8.3.3 | ||
# To generate coverage reports in the Github Actions pipeline | ||
pytest-cov==4.1.0 |