mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-21 13:03:09 -06:00
Test StreamToTopologicalPosition
This commit is contained in:
parent
b4b2c27712
commit
b9754f4591
|
|
@ -217,6 +217,88 @@ func TestGetEventsInRangeWithTopologyToken(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStreamToTopologicalPosition(t *testing.T) {
|
||||||
|
alice := test.NewUser(t)
|
||||||
|
r := test.NewRoom(t, alice)
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
roomID string
|
||||||
|
streamPos types.StreamPosition
|
||||||
|
backwardOrdering bool
|
||||||
|
wantToken types.TopologyToken
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "forward ordering found streamPos returns found position",
|
||||||
|
roomID: r.ID,
|
||||||
|
streamPos: 1,
|
||||||
|
backwardOrdering: false,
|
||||||
|
wantToken: types.TopologyToken{Depth: 1, PDUPosition: 1},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "forward ordering not found streamPos returns max position",
|
||||||
|
roomID: r.ID,
|
||||||
|
streamPos: 100,
|
||||||
|
backwardOrdering: false,
|
||||||
|
wantToken: types.TopologyToken{Depth: math.MaxInt64, PDUPosition: math.MaxInt64},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "backward ordering found streamPos returns found position",
|
||||||
|
roomID: r.ID,
|
||||||
|
streamPos: 1,
|
||||||
|
backwardOrdering: true,
|
||||||
|
wantToken: types.TopologyToken{Depth: 1, PDUPosition: 1},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "backward ordering not found streamPos returns maxDepth with param pduPosition",
|
||||||
|
roomID: r.ID,
|
||||||
|
streamPos: 100,
|
||||||
|
backwardOrdering: true,
|
||||||
|
wantToken: types.TopologyToken{Depth: 5, PDUPosition: 100},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "backward non-existent room returns zero token",
|
||||||
|
roomID: "!doesnotexist:localhost",
|
||||||
|
streamPos: 1,
|
||||||
|
backwardOrdering: true,
|
||||||
|
wantToken: types.TopologyToken{Depth: 0, PDUPosition: 1},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "forward non-existent room returns max token",
|
||||||
|
roomID: "!doesnotexist:localhost",
|
||||||
|
streamPos: 1,
|
||||||
|
backwardOrdering: false,
|
||||||
|
wantToken: types.TopologyToken{Depth: math.MaxInt64, PDUPosition: math.MaxInt64},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
|
||||||
|
db, close, closeBase := MustCreateDatabase(t, dbType)
|
||||||
|
defer close()
|
||||||
|
defer closeBase()
|
||||||
|
|
||||||
|
txn, err := db.NewDatabaseTransaction(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer txn.Rollback()
|
||||||
|
MustWriteEvents(t, db, r.Events())
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
token, err := txn.StreamToTopologicalPosition(ctx, tc.roomID, tc.streamPos, tc.backwardOrdering)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if tc.wantToken != token {
|
||||||
|
t.Fatalf("expected token %q, got %q", tc.wantToken, token)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// The purpose of this test is to make sure that backpagination returns all events, even if some events have the same depth.
|
// The purpose of this test is to make sure that backpagination returns all events, even if some events have the same depth.
|
||||||
// For cases where events have the same depth, the streaming token should be used to tie break so events written via WriteEvent
|
// For cases where events have the same depth, the streaming token should be used to tie break so events written via WriteEvent
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue