summaryrefslogtreecommitdiff
path: root/lib/ldb/tests/python
AgeCommit message (Collapse)AuthorFilesLines
2024-12-19ldb:tests: add tests ensuring indexes don't change search resultsDouglas Bagnall1-0/+478
The index code (lib/ldb_key_value/ldb_kv_index.c) recapitulates LDB expression logic, and it seemed less than completely obvious that it would never make a mistake and return a different result than an unindexed search. Here we run the same search on an unindexed database and on some that have been indexed with a variety of options. We assert that the results are identical over a number of searches. By default, when run from the command line, that number is 495161, which takes a couple of minutes. But if the SKIP_SLOW_TESTS environment variable is set, the number is 33569, which takes 20 seconds or so. In selftest we set the variable and run the smaller number. The tests will print the cumulative search time for each database for each testsuite, like this: $ python3 lib/ldb/tests/python/index_transparency.py ..........................................................[...] <class '__main__.SearchTest'> 25.78186821937561 <ldb connection tdb:///tmp/tmpf1x72x7l/tdb-indexed-dn.ldb> 17.73349642753601 <ldb connection tdb:///tmp/tmpf1x72x7l/tdb-half-indexed.ldb> 15.14864206314087 <ldb connection tdb:///tmp/tmpf1x72x7l/tdb-indexed-guid.ldb> 13.107165575027466 <ldb connection mdb:///tmp/tmpf1x72x7l/mdb-indexed.ldb> Like all benchmarks it is interesting but misleading. One caveat here is that you have (probably) compiled tdb in developer mode without optimisation, while lmdb is probably a system package compiled with -O2, though perhaps not tuned to your exact architecture. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:test:api_search: shift remaining setUp adds to class add_indexDouglas Bagnall1-35/+31
Before: ldb.python.api_search -> 52 ldb.python.api_search.tr -> 48 After: ldb.python.api_search.tr -> 10 ldb.python.api_search -> 9 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Tue Sep 24 10:38:03 UTC 2024 on atb-devel-224
2024-09-24ldb:test:api_search: remove pass-through setUp()sDouglas Bagnall1-9/+0
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:test:api_search: use @unittest.skipIf for LMDB testsDouglas Bagnall1-37/+8
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:test:api_search: skip LMDB tests at class levelDouglas Bagnall1-18/+25
LMDB is not going to turn up midway through the testsuite, so we might as well skip the whole class Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:test:api_search: use class method to add indexDouglas Bagnall1-21/+56
The index attribute of these classes was a mutable object, which made me nervous. If a subclass were to alter the class.index (rather than replace it), it would affect tests in other subclasses. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:test:api_search: tidy up files in each subclassDouglas Bagnall1-2/+8
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:test:api_search: set up the database once and use copiesDouglas Bagnall1-210/+224
The api_search tests are really slow, in part because we populate the database identically for all the individual tests. We can instead do it once and use copies. This makes the test several times faster. Comparing "make test TESTS=ldb.python": Before: TOP 10 slowest tests ldb.python.api_search.tr -> 415 ldb.python.api_search -> 413 ldb.python.api_add_modify -> 5 ldb.python.api_add_modify.tr -> 4 ldb.python.index.tr -> 4 ldb.python.index -> 4 ldb.python.api_simple.tr -> 2 ldb.python.api_simple -> 2 ldb.python.repack -> 2 ldb.python.api_misc.tr -> 1 'testonly' finished successfully (14m13.276s) After: TOP 10 slowest tests ldb.python.api_search.tr -> 52 ldb.python.api_search -> 50 ldb.python.api_add_modify -> 7 ldb.python.api_add_modify.tr -> 7 ldb.python.index.tr -> 4 ldb.python.index -> 4 ldb.python.api_simple -> 4 ldb.python.api_simple.tr -> 2 ldb.python.repack -> 2 ldb.python.api_misc -> 1 'testonly' finished successfully (2m14.505s) Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:test:api_search: use test name as db nameDouglas Bagnall1-2/+6
This will help enusre we are using the right DB when (in the next commit) we set up the database for each test via copy. It also helps with debugging. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:test:api_search: put config options on class, not instance.Douglas Bagnall1-47/+44
This makes them available to class methods. In a later commit we will convert the index attribute into an add_index() class method, because having a mutable variable on a class is a slightly bad idea. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:test:api_search: improve attribute access testsDouglas Bagnall1-3/+3
`list = res.msgs` tests nothing more than a bare `res.msgs`, and we can instead assert that the result is a list. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:test:api_base: make flags method a class methodDouglas Bagnall1-2/+3
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:test:api_base: simplify prefix selectionDouglas Bagnall1-7/+1
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:tests:index: use abi_baseDouglas Bagnall1-12/+6
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:tests:crash: rationalise importsDouglas Bagnall1-2/+1
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:tests:api_simple uses conventional 4 space indentDouglas Bagnall1-3/+3
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:tests:repack: use common api_base variablesDouglas Bagnall1-11/+6
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:tests:api_misc: fix Control testDouglas Bagnall1-1/+1
`self.assertRaises(TypeError, ldb.Control, ldb, 1234)` is raising a TypeError because `ldb` is not an ldb.Ldb object, it is the ldb module. What we want to test here is that the non-string `1234` raises a TypeError -- the previous line tests the type of the ldb argument. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:tests: move api.py to api_miscDouglas Bagnall1-0/+0
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:tests: make api_simple moduleDouglas Bagnall2-732/+752
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:tests: make api_add_modify moduleDouglas Bagnall2-355/+376
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:tests: make api_search moduleDouglas Bagnall2-1698/+1720
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:tests: make api_base moduleDouglas Bagnall2-38/+54
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:tests:api.py uses .disconnect before rmdirDouglas Bagnall1-1/+1
super.tearDown() was removing the tmpdir, but because self.ldb had the file open, the directory was not cleared. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:pytest:api: remove unnecessary super() parametersDouglas Bagnall1-45/+45
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-09-24ldb:pytest:api: remove pass-though tearDownsDouglas Bagnall1-48/+0
The result is exactly the same, unless we previously had the wrong class name in the pass-through, in which case the result is *probably* the same, only more correct. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
2024-05-07ldb:tests: add a test for dotted i uppercaseDouglas Bagnall1-0/+4
This didn't fail in the tr_TR locale before recent changes for https://bugzilla.samba.org/show_bug.cgi?id=15637, because this is a different casefold codepath. But it could fail if that other path goes wrong, so we might as well have the test. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-04-23ldb:pytests: test for Turkic i-dots in ldb_comparison_foldDouglas Bagnall1-0/+16
In tr_TR and some other locales where the letter 'i' uppercases to 'İ', which is not ideal for LDB as we need certain strings like 'guid' to casefold in the ASCII way. In fixing https://bugzilla.samba.org/show_bug.cgi?id=15248) we solved this problem in many cases, but for unindexed searches where the 'i' is not the last character in the string. This test shows that. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15637 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-04-10ldb:pytests: test ldb.connect() works after .disconnect()Douglas Bagnall1-0/+9
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-03-20ldb:pytests: test duplicate connections failDouglas Bagnall1-0/+14
(they don't yet). Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-03-03ldb: Pass a supported opaque type to ldb.set_opaque()Jo Sutton1-1/+1
We are about to modify ldb.set_opaque() to accept only certain types, and ldb.Ldb is not one of those types. Pass in a value that is supported and whose lifetime is guaranteed to outlive the Ldb object. Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-03-03ldb: Add tests for Python set_opaque() and get_opaque()Jo Sutton1-0/+68
Signed-off-by: Jo Sutton <josutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2024-03-03pyldb: Remove unused and broken Python access to LDB module APIAndrew Bartlett1-58/+0
These exposed the private LDB modules API to python, and was untested and broken since LDB was made async internally as it never called ldb_wait() on the result. Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2024-02-29ldb: ldb_string_to_time reports more errorsDouglas Bagnall1-0/+1
The underlying function should return -1 and set errno when given invalid strings, but we were not looking and have decided on 0 for error. It would be a pain to change this function to return -1. Apart from the API fuss, it is sometimes used unchecked to set an unsigned number and an unchecked 0 is better than UINT*_MAX in those contexts. It is probably not easy to get an -1 from a timegm() -- most implementations will happily convert overflows for you, so e.g. the 15th month would be March of the next year. But EOVERFLOW is mentioned in the manpages. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-08-30lib:ldb:tests: Remove explicit comparison with FalseJoseph Sutton1-1/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-04-04lib:ldb:tests: Fix code spellingAndreas Schneider1-4/+4
Best reviewed with: `git show --word-diff`. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Tue Apr 4 08:30:28 UTC 2023 on atb-devel-224
2022-10-05pyldb: Fix tests going unusedJoseph Sutton1-23/+15
These tests are redeclared later and so are never used. Give them new names so that they will be run again. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-09-28pyldb: Add tests for ldb.Message containment testingJoseph Sutton1-0/+23
These tests verify that the 'in' operator on ldb.Message is consistent with indexing and the get() method. This means that the 'dn' element should always be present, lookups should be case-insensitive, and use of an invalid type should result in a TypeError. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14845 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-09-28pyldb: Add test for an invalid ldb.Message index typeJoseph Sutton1-0/+6
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14845 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-06-11pyldb: Add test for Message.items()Joseph Sutton1-0/+21
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2021-03-24CVE-2020-27840: pytests: move Dn.validate test to ldbDouglas Bagnall1-0/+45
We had the test in the Samba Python segfault suite because a) the signal catching infrastructure was there, and b) the ldb tests lack Samba's knownfail mechanism, which allowed us to assert the failure. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14595 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-03-01pyldb: catch potential overflow error in py_timestringStefan Metzmacher1-0/+19
Pair-Programmed-With: Björn Baumbach <bb@sernet.de> Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2021-02-22ldb: remove some 'if PY3's in testsDouglas Bagnall2-44/+17
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: David Mulder <dmulder@suse.com> Autobuild-User(master): David Mulder <dmulder@samba.org> Autobuild-Date(master): Mon Feb 22 15:50:55 UTC 2021 on sn-devel-184
2020-02-25ldb: Add tests aimed at the SCOPE_ONELEVEL bug in particularAndrew Bartlett1-0/+8
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14270 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2020-02-25ldb: Ensure @IDXONE modes is tested in ldb.python (apy.py) testsAndrew Bartlett1-1/+68
Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2020-02-25ldb: Add tests aimed at the SCOPE_ONELEVEL particularAndrew Bartlett1-0/+171
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14270 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2020-02-25ldb: Add tests for one-level indexes in conjunction with other indexesAndrew Bartlett1-0/+251
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14270 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-07-04ldb ldb_key_value: test ldb batchGary Lockyer1-0/+57
Test the the ldb "batch_mode" option sets batch mode operation. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-07-04ldb: Add tests for Ldb.write_ldif() including the FLG_SHOW_BINARY and ↵Andrew Bartlett1-0/+51
FLAG_FORCE_NO_BASE64_LDIF Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2019-06-21lib ldb key value: fix index bufferingGary Lockyer1-1/+81
As a performance enhancement the key value layer maintains a cache of the index records, which is written to disk as part of a prepare commit. This patch adds an extra cache at the operation layer to ensure that the cached indexes remain consistent in the event of an operation failing. Add test to test for index corruption in a failed modify. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org> Signed-off-by: Andrew Bartlett <abartlet@samba.org>