Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannguyen4 committed Oct 23, 2024
1 parent a41d711 commit 0d89565
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
50 changes: 26 additions & 24 deletions test/new_tests/test_free_threading.py
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
2 changes: 1 addition & 1 deletion test/requirements.txt
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

0 comments on commit 0d89565

Please sign in to comment.