Skip to content

Commit

Permalink
Fix randomly failing test `DenseArrayTest::test_open_with_timestamp[F…
Browse files Browse the repository at this point in the history
…alse]` (#2090)
  • Loading branch information
kounelisagis authored Oct 14, 2024
1 parent c6ce3e5 commit 14cae1f
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions tiledb/tests/test_libtiledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,7 @@ def test_open_with_timestamp(self, use_timestamps):
with tiledb.DenseArray(self.path("foo"), mode="w") as T:
T[:] = A

read1_timestamp = -1
with tiledb.DenseArray(self.path("foo"), mode="r") as T:
read1_timestamp = T.timestamp_range
self.assertEqual(T[0], 0)
self.assertEqual(T[1], 0)
self.assertEqual(T[2], 0)
Expand All @@ -849,41 +847,36 @@ def test_open_with_timestamp(self, use_timestamps):
with tiledb.DenseArray(self.path("foo"), mode="w") as T:
T[0:1] = 1

read2_timestamp = -1
with tiledb.DenseArray(self.path("foo"), mode="r") as T:
read2_timestamp = T.timestamp_range
self.assertTrue(read2_timestamp > read1_timestamp)

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

read3_timestamp = -1
with tiledb.DenseArray(self.path("foo"), mode="r") as T:
read3_timestamp = T.timestamp_range
self.assertTrue(read3_timestamp > read2_timestamp > read1_timestamp)
frags = tiledb.array_fragments(self.path("foo"))
# timestamps are in the form of (start, end) for each fragment, with start == end,
# as we are not dealing with consolidated fragments. Let's simply read from 0 to the end timestamp.
read_timestamps = [(0, frag.timestamp_range[1]) for frag in frags]

# read at first timestamp
with tiledb.DenseArray(
self.path("foo"), timestamp=read1_timestamp, mode="r"
self.path("foo"), timestamp=read_timestamps[0], mode="r"
) as T:
self.assertEqual(T[0], 0)
self.assertEqual(T[1], 0)
self.assertEqual(T[2], 0)

# read at second timestamp
with tiledb.DenseArray(
self.path("foo"), timestamp=read2_timestamp, mode="r"
self.path("foo"), timestamp=read_timestamps[1], mode="r"
) as T:
self.assertEqual(T[0], 1)
self.assertEqual(T[1], 0)
self.assertEqual(T[2], 0)

# read at third timestamp
with tiledb.DenseArray(
self.path("foo"), timestamp=read3_timestamp, mode="r"
self.path("foo"), timestamp=read_timestamps[2], mode="r"
) as T:
self.assertEqual(T[0], 1)
self.assertEqual(T[1], 2)
Expand Down

0 comments on commit 14cae1f

Please sign in to comment.