mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 11:16:07 -04:00
Test and fix find_first_stream_ordering_after_ts
It seemed to suffer from a bunch of off-by-one errors.
This commit is contained in:
parent
06a14876e5
commit
c818fcab11
2 changed files with 119 additions and 14 deletions
|
@ -127,3 +127,70 @@ class EventPushActionsStoreTestCase(tests.unittest.TestCase):
|
|||
yield _assert_counts(1, 1)
|
||||
yield _rotate(10)
|
||||
yield _assert_counts(1, 1)
|
||||
|
||||
@tests.unittest.DEBUG
|
||||
@defer.inlineCallbacks
|
||||
def test_find_first_stream_ordering_after_ts(self):
|
||||
def add_event(so, ts):
|
||||
return self.store._simple_insert("events", {
|
||||
"stream_ordering": so,
|
||||
"received_ts": ts,
|
||||
"event_id": "event%i" % so,
|
||||
"type": "",
|
||||
"room_id": "",
|
||||
"content": "",
|
||||
"processed": True,
|
||||
"outlier": False,
|
||||
"topological_ordering": 0,
|
||||
"depth": 0,
|
||||
})
|
||||
|
||||
# start with the base case where there are no events in the table
|
||||
r = yield self.store.find_first_stream_ordering_after_ts(11)
|
||||
self.assertEqual(r, 0)
|
||||
|
||||
# now with one event
|
||||
yield add_event(2, 10)
|
||||
r = yield self.store.find_first_stream_ordering_after_ts(9)
|
||||
self.assertEqual(r, 2)
|
||||
r = yield self.store.find_first_stream_ordering_after_ts(10)
|
||||
self.assertEqual(r, 2)
|
||||
r = yield self.store.find_first_stream_ordering_after_ts(11)
|
||||
self.assertEqual(r, 3)
|
||||
|
||||
# add a bunch of dummy events to the events table
|
||||
for (stream_ordering, ts) in (
|
||||
(3, 110),
|
||||
(4, 120),
|
||||
(5, 120),
|
||||
(10, 130),
|
||||
(20, 140),
|
||||
):
|
||||
yield add_event(stream_ordering, ts)
|
||||
|
||||
r = yield self.store.find_first_stream_ordering_after_ts(110)
|
||||
self.assertEqual(r, 3,
|
||||
"First event after 110ms should be 3, was %i" % r)
|
||||
|
||||
# 4 and 5 are both after 12: we want 4 rather than 5
|
||||
r = yield self.store.find_first_stream_ordering_after_ts(120)
|
||||
self.assertEqual(r, 4,
|
||||
"First event after 120ms should be 4, was %i" % r)
|
||||
|
||||
r = yield self.store.find_first_stream_ordering_after_ts(129)
|
||||
self.assertEqual(r, 10,
|
||||
"First event after 129ms should be 10, was %i" % r)
|
||||
|
||||
# check we can get the last event
|
||||
r = yield self.store.find_first_stream_ordering_after_ts(140)
|
||||
self.assertEqual(r, 20,
|
||||
"First event after 14ms should be 20, was %i" % r)
|
||||
|
||||
# off the end
|
||||
r = yield self.store.find_first_stream_ordering_after_ts(160)
|
||||
self.assertEqual(r, 21)
|
||||
|
||||
# check we can find an event at ordering zero
|
||||
yield add_event(0, 5)
|
||||
r = yield self.store.find_first_stream_ordering_after_ts(1)
|
||||
self.assertEqual(r, 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue