mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Remove nil guards, give roomserver integration test a cache
This commit is contained in:
parent
1373929ffc
commit
7b777d80d1
|
|
@ -28,6 +28,7 @@ import (
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/common/caching"
|
||||||
"github.com/matrix-org/dendrite/common/test"
|
"github.com/matrix-org/dendrite/common/test"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
|
@ -253,6 +254,11 @@ func testRoomserver(input []string, wantOutput []string, checkQueries func(api.R
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cache, err := caching.NewImmutableInMemoryLRUCache()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
doInput := func() {
|
doInput := func() {
|
||||||
fmt.Printf("Roomserver is ready to receive input, sending %d events\n", len(input))
|
fmt.Printf("Roomserver is ready to receive input, sending %d events\n", len(input))
|
||||||
if err = writeToRoomServer(input, cfg.RoomServerURL()); err != nil {
|
if err = writeToRoomServer(input, cfg.RoomServerURL()); err != nil {
|
||||||
|
|
@ -270,7 +276,7 @@ func testRoomserver(input []string, wantOutput []string, checkQueries func(api.R
|
||||||
cmd.Args = []string{"dendrite-room-server", "--config", filepath.Join(dir, test.ConfigFile)}
|
cmd.Args = []string{"dendrite-room-server", "--config", filepath.Join(dir, test.ConfigFile)}
|
||||||
|
|
||||||
gotOutput, err := runAndReadFromTopic(cmd, cfg.RoomServerURL()+"/metrics", doInput, outputTopic, len(wantOutput), func() {
|
gotOutput, err := runAndReadFromTopic(cmd, cfg.RoomServerURL()+"/metrics", doInput, outputTopic, len(wantOutput), func() {
|
||||||
queryAPI, _ := api.NewRoomserverQueryAPIHTTP("http://"+string(cfg.Listen.RoomServer), &http.Client{Timeout: timeoutHTTP}, nil)
|
queryAPI, _ := api.NewRoomserverQueryAPIHTTP("http://"+string(cfg.Listen.RoomServer), &http.Client{Timeout: timeoutHTTP}, cache)
|
||||||
checkQueries(queryAPI)
|
checkQueries(queryAPI)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,6 @@ func checkForInvalidMutation(cache *lru.Cache, key string, value interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ImmutableInMemoryLRUCache) GetRoomVersion(roomID string) (gomatrixserverlib.RoomVersion, bool) {
|
func (c *ImmutableInMemoryLRUCache) GetRoomVersion(roomID string) (gomatrixserverlib.RoomVersion, bool) {
|
||||||
if c == nil {
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
val, found := c.roomVersions.Get(roomID)
|
val, found := c.roomVersions.Get(roomID)
|
||||||
if found && val != nil {
|
if found && val != nil {
|
||||||
if roomVersion, ok := val.(gomatrixserverlib.RoomVersion); ok {
|
if roomVersion, ok := val.(gomatrixserverlib.RoomVersion); ok {
|
||||||
|
|
@ -41,9 +38,6 @@ func (c *ImmutableInMemoryLRUCache) GetRoomVersion(roomID string) (gomatrixserve
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ImmutableInMemoryLRUCache) StoreRoomVersion(roomID string, roomVersion gomatrixserverlib.RoomVersion) {
|
func (c *ImmutableInMemoryLRUCache) StoreRoomVersion(roomID string, roomVersion gomatrixserverlib.RoomVersion) {
|
||||||
if c == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
checkForInvalidMutation(c.roomVersions, roomID, roomVersion)
|
checkForInvalidMutation(c.roomVersions, roomID, roomVersion)
|
||||||
c.roomVersions.Add(roomID, roomVersion)
|
c.roomVersions.Add(roomID, roomVersion)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue