Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d353c33
None of the test cases in test_query modify the records inserted by t…
juliannguyen4 Oct 29, 2025
0268b94
Optimize test_query_partition.py
juliannguyen4 Oct 29, 2025
ebfbd3a
fix test
juliannguyen4 Oct 29, 2025
a586168
Move from old syntax
juliannguyen4 Oct 29, 2025
94ee2f5
fix test..
juliannguyen4 Oct 29, 2025
4a38ea1
no longer using config funcs
juliannguyen4 Oct 29, 2025
22dfaba
Fix
juliannguyen4 Oct 30, 2025
3e68ae8
fix
juliannguyen4 Oct 30, 2025
7376d37
this one works
juliannguyen4 Oct 30, 2025
f2a7549
Optimize query pagination test
juliannguyen4 Oct 30, 2025
58153d9
do the same here
juliannguyen4 Oct 30, 2025
f14a460
optimize
juliannguyen4 Oct 30, 2025
f68c327
fix
juliannguyen4 Oct 30, 2025
1995a3d
optimize test_scan
juliannguyen4 Oct 30, 2025
400f7fa
optimize
juliannguyen4 Oct 30, 2025
c2cc7f4
Finish optimizing scans.
juliannguyen4 Oct 30, 2025
b580c8a
Optimize a subset of the admin command tests
juliannguyen4 Oct 30, 2025
f9ea257
Fix test code
juliannguyen4 Oct 31, 2025
f8b7e80
Fix test
juliannguyen4 Oct 31, 2025
54860eb
optimize the remaining admin tests.
juliannguyen4 Oct 31, 2025
7ca1c92
fix
juliannguyen4 Oct 31, 2025
cd8efd5
fix
juliannguyen4 Oct 31, 2025
7c9855b
Introduce hard limit to prevent hanging
juliannguyen4 Oct 31, 2025
698f3b9
Helpful logs
juliannguyen4 Oct 31, 2025
8431c9b
Show when max timeout is hit
juliannguyen4 Oct 31, 2025
d6bc519
fix test
juliannguyen4 Oct 31, 2025
1248abb
fix
juliannguyen4 Oct 31, 2025
facbb8d
Fix test. also one small opt
juliannguyen4 Oct 31, 2025
1287f5f
Try making class fixture autouse when defined inside class. not sure …
juliannguyen4 Oct 31, 2025
8e9ca71
Fix test
juliannguyen4 Oct 31, 2025
bce1780
Workaround to set class attributes from class fixture.
juliannguyen4 Oct 31, 2025
db33a2d
Test using wait_for_job_completion instead of a hardcoded timeout of …
juliannguyen4 Nov 3, 2025
8e7c92a
Introduce hard limit so test doesn't hang
juliannguyen4 Nov 3, 2025
48a74b3
fix
juliannguyen4 Nov 3, 2025
fd4b53c
Refactor code using wait helper. TODO add five second hard limit for …
juliannguyen4 Nov 3, 2025
a1136de
Turn print statements into logs to make easier to debug whenever needed
juliannguyen4 Nov 3, 2025
1cc3f88
optimize more admin tests. TODO need to refactor these...
juliannguyen4 Nov 3, 2025
b1887fc
Fix
juliannguyen4 Nov 3, 2025
f62748d
Try monkeypatching admin_query_role so it includes polling logic
juliannguyen4 Nov 4, 2025
560f8ec
First successful attempt
juliannguyen4 Nov 4, 2025
fe39b74
Refactor
juliannguyen4 Nov 4, 2025
cac3d32
Apply this to all tests. TODO check performance
juliannguyen4 Nov 4, 2025
f7ea60e
Fix
juliannguyen4 Nov 4, 2025
091a70e
Fix
juliannguyen4 Nov 4, 2025
f8e57d6
Use a wrapper helper function instead of monkeypatching since the cli…
juliannguyen4 Nov 4, 2025
de9cf15
Fix
juliannguyen4 Nov 4, 2025
634b719
Fix
juliannguyen4 Nov 4, 2025
a61b6fe
Fix tests missing arg
juliannguyen4 Nov 4, 2025
e8bce77
Fix
juliannguyen4 Nov 4, 2025
51021e3
fix tests. TODO think of using auto imports
juliannguyen4 Nov 4, 2025
d9e7ed8
Fix test
juliannguyen4 Nov 4, 2025
a32a708
Fix remainder
juliannguyen4 Nov 4, 2025
aa9a06c
Fix
juliannguyen4 Nov 4, 2025
2fb3663
Fix tests
juliannguyen4 Nov 4, 2025
2dd4218
More optimizing. Remove unneeded timeouts
juliannguyen4 Nov 5, 2025
4b4e56f
Fix
juliannguyen4 Nov 5, 2025
e5dc07d
Fix ce tests...
juliannguyen4 Nov 5, 2025
394b9a4
Rm bad polling
juliannguyen4 Nov 5, 2025
f2ac553
Unused
juliannguyen4 Nov 5, 2025
2f86986
Merge remote-tracking branch 'origin/dev' into CLIENT-3846-speed-up-a…
juliannguyen4 Nov 13, 2025
5f24d60
Wait for user to have expected roles
juliannguyen4 Nov 13, 2025
8f0b86f
Rm redundant checks since polling helper functions already do the sam…
juliannguyen4 Nov 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 92 additions & 1 deletion test/new_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import sys

import pytest

from . import invalid_data
from .test_base_class import TestBaseClass

import aerospike
from aerospike import exception as e
import logging


# Comment this out because nowhere in the repository is using it
'''
Expand Down Expand Up @@ -241,3 +243,92 @@ def invalid_key(request):

# aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG)
# aerospike.set_log_handler(None)

HARD_LIMIT_SECS = 3
# Server team states that this time interval is a safe amount
POLL_INTERVAL_SECS = 0.1

def poll_until_role_exists(role_name: str, client: aerospike.Client):
start = time.time()
while time.time() - start < HARD_LIMIT_SECS:
try:
client.admin_query_role(role=role_name)
except e.InvalidRole:
time.sleep(POLL_INTERVAL_SECS)
continue
logging.debug("Role now exists. Return early")
return
logging.debug("poll_until_role_exists timeout")

def poll_until_role_doesnt_exist(role_name: str, client: aerospike.Client):
start = time.time()
try:
while time.time() - start < HARD_LIMIT_SECS:
client.admin_query_role(role=role_name)
time.sleep(POLL_INTERVAL_SECS)
except e.InvalidRole:
logging.debug("Role no longer exists. Return early")
return
logging.debug("poll_until_role_doesnt_exist timeout")

def poll_until_user_exists(username: str, client: aerospike.Client, roles: list[str]):
start = time.time()
while time.time() - start < HARD_LIMIT_SECS:
try:
user_dict = client.admin_query_user_info(user=username)
if user_dict["roles"] != roles:
continue
except e.InvalidUser:
time.sleep(POLL_INTERVAL_SECS)
continue
logging.debug("User now exists with expected roles.")
return
logging.debug("poll_until_user_exists timeout")

def poll_until_user_doesnt_exist(username: str, client: aerospike.Client):
start = time.time()
try:
while time.time() - start < HARD_LIMIT_SECS:
client.admin_query_user_info(user=username)
time.sleep(POLL_INTERVAL_SECS)
except e.InvalidUser:
logging.debug("User no longer exists. Return early")
return
logging.debug("poll_until_user_doesnt_exist timeout")

def wait_for_job_completion(as_connection, job_id, job_module: int = aerospike.JOB_QUERY, time_limit_secs: float = float("inf")):
"""
Blocks until the job has completed
"""
start = time.time()
while time.time() - start < time_limit_secs:
response = as_connection.job_info(job_id, job_module)
if response["status"] != aerospike.JOB_STATUS_INPROGRESS:
break
time.sleep(0.1)

# Monkeypatching the client class or instance isn't possible since it's immutable

def admin_create_role_and_poll(client: aerospike.Client, role: str, *args, **kwargs):
retval = client.admin_create_role(role, *args, **kwargs)
poll_until_role_exists(role, client)
return retval

def admin_create_user_and_poll(client: aerospike.Client, username: str, password: str, roles: list, *args, **kwargs):
retval = client.admin_create_user(username, password, roles, *args, **kwargs)

# The server creates a user and adds roles to it asynchronously, since security is a type of smd operation
# So client.admin_create_user() can return before all th
poll_until_user_exists(username, client, roles)

return retval

def admin_drop_user_and_poll(client: aerospike.Client, username: str, *args, **kwargs):
retval = client.admin_drop_user(username, *args, **kwargs)
poll_until_user_doesnt_exist(username, client)
return retval

def admin_drop_role_and_poll(client: aerospike.Client, role: str, *args, **kwargs):
retval = client.admin_drop_role(role, *args, **kwargs)
poll_until_role_doesnt_exist(role, client)
return retval
37 changes: 25 additions & 12 deletions test/new_tests/test_admin_change_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,32 @@
import pytest
import time
from .test_base_class import TestBaseClass
from .conftest import admin_drop_user_and_poll, poll_until_user_doesnt_exist

import aerospike


@pytest.mark.usefixtures("connection_config")
class TestChangePassword(object):
class TestChangePassword:
def setup_method(self, method):
"""
Setup method
"""
if TestBaseClass.auth_in_use() is False:
pytest.skip("No user specified, may not be a secured cluster", allow_module_level=True)
pytest.skip(
"No user specified, may not be a secured cluster",
allow_module_level=True,
)

config = TestBaseClass.get_connection_config()
self.client = aerospike.client(config).connect(config["user"], config["password"])
self.client = aerospike.client(config).connect(
config["user"], config["password"]
)

try:
self.client.admin_create_user("testchangepassworduser", "aerospike", ["read"])
time.sleep(2)
self.client.admin_create_user(
"testchangepassworduser", "aerospike", ["read"]
)
except aerospike.exception.UserExistsError:
pass # we are good, no such role exists
self.delete_users = []
Expand All @@ -32,7 +39,7 @@ def teardown_method(self, method):
"""

try:
self.client.admin_drop_user("testchangepassworduser")
admin_drop_user_and_poll(self.client, "testchangepassworduser")
except Exception:
pass

Expand All @@ -56,13 +63,15 @@ def test_change_password_with_proper_parameters(self):
status = self.clientreaduser.admin_change_password(user, password)

assert status == 0

time.sleep(2)
config = self.connection_config

# Assert that connecting to the server with the old password fails
with pytest.raises((aerospike.exception.InvalidPassword, aerospike.exception.InvalidCredential)):
self.clientreaduserwrong = aerospike.client(config).connect(user, "aerospike")
with pytest.raises(
(aerospike.exception.InvalidPassword, aerospike.exception.InvalidCredential)
):
self.clientreaduserwrong = aerospike.client(config).connect(
user, "aerospike"
)

self.clientreaduserright = aerospike.client(config).connect(user, "newpassword")

Expand Down Expand Up @@ -101,8 +110,12 @@ def test_change_password_with_proper_timeout_policy_value(self):
time.sleep(2)
config = self.connection_config

with pytest.raises((aerospike.exception.InvalidPassword, aerospike.exception.InvalidCredential)):
self.clientreaduserwrong = aerospike.client(config).connect(user, "aerospike")
with pytest.raises(
(aerospike.exception.InvalidPassword, aerospike.exception.InvalidCredential)
):
self.clientreaduserwrong = aerospike.client(config).connect(
user, "aerospike"
)

self.clientreaduserright = aerospike.client(config).connect(user, "newpassword")

Expand Down
Loading
Loading