Skip to content

Commit c8c687a

Browse files
authored
Eliminate hacky use of timestamps and time.sleep in tests (#2120)
1 parent f72e528 commit c8c687a

File tree

5 files changed

+31
-85
lines changed

5 files changed

+31
-85
lines changed

tiledb/tests/cc/test_group.py

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def test_group_metadata(tmp_path):
2828
assert_array_equal(grp._get_metadata("flt", False)[0], flt_data)
2929
grp._close()
3030

31-
time.sleep(0.001)
3231
grp._open(lt.QueryType.WRITE)
3332
grp._delete_metadata("int")
3433
grp._close()

tiledb/tests/test_fixes.py

+5-16
Original file line numberDiff line numberDiff line change
@@ -364,26 +364,16 @@ class SOMA919Test(DiskTestCase):
364364
We've distilled @atolopko-czi's gist example using the TileDB-Py API directly.
365365
"""
366366

367-
def run_test(self, use_timestamps):
367+
def run_test(self):
368368
import tempfile
369369

370370
import numpy as np
371371

372372
import tiledb
373373

374374
root_uri = tempfile.mkdtemp()
375-
376-
if use_timestamps:
377-
group_ctx100 = tiledb.Ctx(
378-
{
379-
"sm.group.timestamp_start": 100,
380-
"sm.group.timestamp_end": 100,
381-
}
382-
)
383-
timestamp = 100
384-
else:
385-
group_ctx100 = tiledb.Ctx()
386-
timestamp = None
375+
group_ctx100 = tiledb.Ctx()
376+
timestamp = None
387377

388378
# create the group and add a dummy subgroup "causes_bug"
389379
tiledb.Group.create(root_uri, ctx=group_ctx100)
@@ -411,13 +401,12 @@ def run_test(self, use_timestamps):
411401
tiledb.libtiledb.version() < (2, 15, 0),
412402
reason="SOMA919 fix implemented in libtiledb 2.15",
413403
)
414-
@pytest.mark.parametrize("use_timestamps", [True, False])
415-
def test_soma919(self, use_timestamps):
404+
def test_soma919(self):
416405
N = 100
417406
fails = 0
418407
for i in range(N):
419408
try:
420-
self.run_test(use_timestamps)
409+
self.run_test()
421410
except AssertionError:
422411
fails += 1
423412
if fails > 0:

tiledb/tests/test_group.py

+14-19
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,7 @@ def test_move_group(self):
120120
),
121121
),
122122
)
123-
@pytest.mark.parametrize("use_timestamps", [True, False])
124-
def test_group_metadata(
125-
self, int_data, flt_data, str_data, str_type, capfd, use_timestamps
126-
):
123+
def test_group_metadata(self, int_data, flt_data, str_data, str_type, capfd):
127124
def values_equal(lhs, rhs):
128125
if isinstance(lhs, np.ndarray):
129126
if not isinstance(rhs, np.ndarray):
@@ -139,13 +136,13 @@ def values_equal(lhs, rhs):
139136
grp_path = self.path("test_group_metadata")
140137
tiledb.Group.create(grp_path)
141138

142-
cfg = tiledb.Config({"sm.group.timestamp_end": 1} if use_timestamps else {})
139+
cfg = tiledb.Config()
143140
with tiledb.Group(grp_path, "w", cfg) as grp:
144141
grp.meta["int"] = int_data
145142
grp.meta["flt"] = flt_data
146143
grp.meta["str"] = str_data
147144

148-
cfg = tiledb.Config({"sm.group.timestamp_end": 1} if use_timestamps else {})
145+
cfg = tiledb.Config()
149146
with tiledb.Group(grp_path, "r", cfg) as grp:
150147
assert len(grp.meta) == 3
151148
assert "int" in grp.meta
@@ -162,11 +159,11 @@ def values_equal(lhs, rhs):
162159
assert "Type: DataType.INT" in metadata_dump
163160
assert f"Type: DataType.{str_type}" in metadata_dump
164161

165-
cfg = tiledb.Config({"sm.group.timestamp_end": 2} if use_timestamps else {})
162+
cfg = tiledb.Config()
166163
with tiledb.Group(grp_path, "w", cfg) as grp:
167164
del grp.meta["int"]
168165

169-
cfg = tiledb.Config({"sm.group.timestamp_end": 2} if use_timestamps else {})
166+
cfg = tiledb.Config()
170167
with tiledb.Group(grp_path, "r", cfg) as grp:
171168
assert len(grp.meta) == 2
172169
assert "int" not in grp.meta
@@ -373,8 +370,7 @@ class GroupMetadataTest(GroupTestCase):
373370
(np.array([1, 2, 3]), np.array([1.5, 2.5, 3.5]), np.array(["x"])),
374371
),
375372
)
376-
@pytest.mark.parametrize("use_timestamps", [True, False])
377-
def test_group_metadata(self, int_data, flt_data, str_data, use_timestamps):
373+
def test_group_metadata(self, int_data, flt_data, str_data):
378374
def values_equal(lhs, rhs):
379375
if isinstance(lhs, np.ndarray):
380376
if not isinstance(rhs, np.ndarray):
@@ -390,13 +386,13 @@ def values_equal(lhs, rhs):
390386
grp_path = self.path("test_group_metadata")
391387
tiledb.Group.create(grp_path)
392388

393-
cfg = tiledb.Config({"sm.group.timestamp_end": 1} if use_timestamps else {})
389+
cfg = tiledb.Config()
394390
with tiledb.Group(grp_path, "w", cfg) as grp:
395391
grp.meta["int"] = int_data
396392
grp.meta["flt"] = flt_data
397393
grp.meta["str"] = str_data
398394

399-
cfg = tiledb.Config({"sm.group.timestamp_end": 1} if use_timestamps else {})
395+
cfg = tiledb.Config()
400396
with tiledb.Group(grp_path, "r", cfg) as grp:
401397
assert grp.meta.keys() == {"int", "flt", "str"}
402398
assert len(grp.meta) == 3
@@ -407,11 +403,11 @@ def values_equal(lhs, rhs):
407403
assert "str" in grp.meta
408404
assert values_equal(grp.meta["str"], str_data)
409405

410-
cfg = tiledb.Config({"sm.group.timestamp_end": 2} if use_timestamps else {})
406+
cfg = tiledb.Config()
411407
with tiledb.Group(grp_path, "w", cfg) as grp:
412408
del grp.meta["int"]
413409

414-
cfg = tiledb.Config({"sm.group.timestamp_end": 2} if use_timestamps else {})
410+
cfg = tiledb.Config()
415411
with tiledb.Group(grp_path, "r", cfg) as grp:
416412
assert len(grp.meta) == 2
417413
assert "int" not in grp.meta
@@ -641,21 +637,20 @@ def test_numpy(self, test_vals, ndarray):
641637
self.assert_metadata_roundtrip(grp.meta, test_vals)
642638
grp.close()
643639

644-
@pytest.mark.parametrize("use_timestamps", [True, False])
645-
def test_consolidation_and_vac(self, use_timestamps):
640+
def test_consolidation_and_vac(self):
646641
vfs = tiledb.VFS()
647642
path = self.path("test_consolidation_and_vac")
648643
tiledb.Group.create(path)
649644

650-
cfg = tiledb.Config({"sm.group.timestamp_end": 1} if use_timestamps else {})
645+
cfg = tiledb.Config()
651646
with tiledb.Group(path, "w", cfg) as grp:
652647
grp.meta["meta"] = 1
653648

654-
cfg = tiledb.Config({"sm.group.timestamp_end": 2} if use_timestamps else {})
649+
cfg = tiledb.Config()
655650
with tiledb.Group(path, "w", cfg) as grp:
656651
grp.meta["meta"] = 2
657652

658-
cfg = tiledb.Config({"sm.group.timestamp_end": 3} if use_timestamps else {})
653+
cfg = tiledb.Config()
659654
with tiledb.Group(path, "w", cfg) as grp:
660655
grp.meta["meta"] = 3
661656

tiledb/tests/test_libtiledb.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,7 @@ def test_ncell_int(self):
823823
assert_array_equal(T, R)
824824
assert_array_equal(T, R.multi_index[0:2][""])
825825

826-
@pytest.mark.parametrize("use_timestamps", [True, False])
827-
def test_open_with_timestamp(self, use_timestamps):
826+
def test_open_with_timestamp(self):
828827
A = np.zeros(3)
829828

830829
dom = tiledb.Domain(tiledb.Dim(domain=(0, 2), tile=3, dtype=np.int64))
@@ -841,15 +840,9 @@ def test_open_with_timestamp(self, use_timestamps):
841840
self.assertEqual(T[1], 0)
842841
self.assertEqual(T[2], 0)
843842

844-
if use_timestamps:
845-
# sleep 200ms and write
846-
time.sleep(0.2)
847843
with tiledb.DenseArray(self.path("foo"), mode="w") as T:
848844
T[0:1] = 1
849845

850-
if use_timestamps:
851-
# sleep 200ms and write
852-
time.sleep(0.2)
853846
with tiledb.DenseArray(self.path("foo"), mode="w") as T:
854847
T[1:2] = 2
855848

tiledb/tests/test_metadata.py

+11-41
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ def test_basic(self, test_vals):
189189

190190
@given(st_metadata, st_ndarray)
191191
@settings(deadline=None)
192-
@pytest.mark.parametrize("use_timestamps", [True, False])
193-
def test_numpy(self, use_timestamps, test_vals, ndarray):
192+
def test_numpy(self, test_vals, ndarray):
194193
test_vals["ndarray"] = ndarray
195194

196195
path = self.path()
@@ -203,9 +202,6 @@ def test_numpy(self, use_timestamps, test_vals, ndarray):
203202
with tiledb.Array(path) as A:
204203
self.assert_metadata_roundtrip(A.meta, test_vals)
205204

206-
if use_timestamps:
207-
# test resetting a key with a ndarray value to a non-ndarray value
208-
time.sleep(0.001)
209205
with tiledb.Array(path, "w") as A:
210206
A.meta["ndarray"] = 42
211207
test_vals["ndarray"] = 42
@@ -221,19 +217,13 @@ def test_numpy(self, use_timestamps, test_vals, ndarray):
221217
with tiledb.Array(path) as A:
222218
self.assert_metadata_roundtrip(A.meta, test_vals)
223219

224-
if use_timestamps:
225-
# test del ndarray key
226-
time.sleep(0.001)
227220
with tiledb.Array(path, "w") as A:
228221
del A.meta["ndarray"]
229222
del test_vals["ndarray"]
230223

231224
with tiledb.Array(path) as A:
232225
self.assert_metadata_roundtrip(A.meta, test_vals)
233226

234-
if use_timestamps:
235-
# test update
236-
time.sleep(0.001)
237227
with tiledb.Array(path, mode="w") as A:
238228
test_vals.update(ndarray=np.stack([ndarray, ndarray]), transp=ndarray.T)
239229
A.meta.update(ndarray=np.stack([ndarray, ndarray]), transp=ndarray.T)
@@ -245,8 +235,7 @@ def test_numpy(self, use_timestamps, test_vals, ndarray):
245235
@tiledb.scope_ctx(
246236
{"sm.vacuum.mode": "array_meta", "sm.consolidation.mode": "array_meta"}
247237
)
248-
@pytest.mark.parametrize("use_timestamps", [True, False])
249-
def test_consecutive(self, use_timestamps):
238+
def test_consecutive(self):
250239
vfs = tiledb.VFS()
251240
path = self.path("test_md_consecutive")
252241

@@ -259,17 +248,10 @@ def test_consecutive(self, use_timestamps):
259248
randutf8s = [rand_utf8(i) for i in np.random.randint(1, 30, size=write_count)]
260249

261250
# write 100 times, then consolidate
262-
if use_timestamps:
263-
for i in range(write_count):
264-
with tiledb.Array(path, mode="w") as A:
265-
A.meta["randint"] = int(randints[i])
266-
A.meta["randutf8"] = randutf8s[i]
267-
time.sleep(0.001)
268-
else:
269-
for i in range(write_count):
270-
with tiledb.Array(path, mode="w") as A:
271-
A.meta["randint"] = int(randints[i])
272-
A.meta["randutf8"] = randutf8s[i]
251+
for i in range(write_count):
252+
with tiledb.Array(path, mode="w") as A:
253+
A.meta["randint"] = int(randints[i])
254+
A.meta["randutf8"] = randutf8s[i]
273255

274256
self.assertEqual(len(vfs.ls(os.path.join(path, "__meta"))), 100)
275257

@@ -296,23 +278,11 @@ def test_consecutive(self, use_timestamps):
296278
self.assertEqual(A.meta["randutf8"], randutf8s[-1])
297279

298280
# use randutf8s as keys, then consolidate
299-
if use_timestamps:
300-
for _ in range(2):
301-
for i in range(write_count):
302-
with tiledb.Array(path, mode="w") as A:
303-
A.meta[randutf8s[i] + "{}".format(randints[i])] = int(
304-
randints[i]
305-
)
306-
A.meta[randutf8s[i]] = randutf8s[i]
307-
time.sleep(0.001)
308-
else:
309-
for _ in range(2):
310-
for i in range(write_count):
311-
with tiledb.Array(path, mode="w") as A:
312-
A.meta[randutf8s[i] + "{}".format(randints[i])] = int(
313-
randints[i]
314-
)
315-
A.meta[randutf8s[i]] = randutf8s[i]
281+
for _ in range(2):
282+
for i in range(write_count):
283+
with tiledb.Array(path, mode="w") as A:
284+
A.meta[randutf8s[i] + "{}".format(randints[i])] = int(randints[i])
285+
A.meta[randutf8s[i]] = randutf8s[i]
316286

317287
# test data
318288
with tiledb.Array(path) as A:

0 commit comments

Comments
 (0)