| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2016 Red Hat, Inc. |
| 3 |
# All rights reserved. |
| 4 |
# |
| 5 |
# License: GPL (version 3 or any later version). |
| 6 |
# See LICENSE for details. |
| 7 |
# --- END COPYRIGHT BLOCK --- |
| 8 |
# |
| 9 |
import pytest |
| 10 |
from lib389.tasks import * |
| 11 |
from lib389.utils import * |
| 12 |
from lib389.paths import Paths |
| 13 |
from test389.topologies import topology_st |
| 14 |
from lib389._constants import * |
| 15 |
|
| 16 |
pytestmark = pytest.mark.tier2 |
| 17 |
|
| 18 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 19 |
log = logging.getLogger(__name__) |
| 20 |
|
| 21 |
ds_paths = Paths() |
| 22 |
|
| 23 |
|
| 24 |
@pytest.mark.skipif(not ds_paths.asan_enabled, reason="Don't run if ASAN is not enabled") |
| 25 |
def test_range_search(topology_st): |
| 26 |
"""Add 100 entries, and run a range search. When we encounter an error |
| 27 |
we still need to disable valgrind before exiting |
| 28 |
|
| 29 |
:id: aadccf78-a2a8-48cc-8769-4764c7966189 |
| 30 |
:setup: Standalone instance, Retro changelog file, |
| 31 |
Enabled Valgrind if the system doesn't have asan |
| 32 |
:steps: |
| 33 |
1. Add 100 test entries |
| 34 |
2. Issue a range search with a changenumber filter |
| 35 |
3. There should be no leak |
| 36 |
:expectedresults: |
| 37 |
1. 100 test entries should be added |
| 38 |
2. Search should be successful |
| 39 |
3. Success |
| 40 |
""" |
| 41 |
|
| 42 |
log.info('Running test_range_search...') |
| 43 |
topology_st.standalone.plugins.enable(name=PLUGIN_RETRO_CHANGELOG) |
| 44 |
topology_st.standalone.restart() |
| 45 |
|
| 46 |
success = True |
| 47 |
|
| 48 |
# Add 100 test entries |
| 49 |
for idx in range(1, 100): |
| 50 |
idx = str(idx) |
| 51 |
USER_DN = 'uid=user' + idx + ',' + DEFAULT_SUFFIX |
| 52 |
try: |
| 53 |
topology_st.standalone.add_s(Entry((USER_DN, {'objectclass': "top extensibleObject".split(), |
| 54 |
'uid': 'user' + idx}))) |
| 55 |
except ldap.LDAPError as e: |
| 56 |
log.fatal('test_range_search: Failed to add test user ' + USER_DN + ': error ' + e.message['desc']) |
| 57 |
success = False |
| 58 |
time.sleep(1) |
| 59 |
|
| 60 |
# Issue range search |
| 61 |
assert success |
| 62 |
entries = topology_st.standalone.search_s(RETROCL_SUFFIX, ldap.SCOPE_SUBTREE, |
| 63 |
'(&(changenumber>=74)(changenumber<=84))') |
| 64 |
assert entries |
| 65 |
|
| 66 |
|
| 67 |
if __name__ == '__main__': |
| 68 |
# Run isolated |
| 69 |
# -s for DEBUG mode |
| 70 |
CURRENT_FILE = os.path.realpath(__file__) |
| 71 |
pytest.main("-s %s" % CURRENT_FILE) |