Skip to content

Commit

Permalink
see what happens
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannguyen4 committed Oct 23, 2024
1 parent 8be436d commit a41d711
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions test/new_tests/test_free_threading.py
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

0 comments on commit a41d711

Please sign in to comment.