Begin adding syncapi component tests (#2442)

* Add very basic syncapi tests

* Add a way to inject jetstream messages

* implement add_state_ids

* bugfixes

* Unbreak tests

* Remove now un-needed API call

* Linting
This commit is contained in:
kegsay 2022-05-09 17:23:02 +01:00 committed by GitHub
parent a443d1e5f3
commit 236b16aa6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 337 additions and 11 deletions

View file

@ -86,6 +86,7 @@ type BaseDendrite struct {
DNSCache *gomatrixserverlib.DNSCache
Database *sql.DB
DatabaseWriter sqlutil.Writer
EnableMetrics bool
}
const NoListener = ""
@ -96,7 +97,7 @@ const HTTPClientTimeout = time.Second * 30
type BaseDendriteOptions int
const (
NoCacheMetrics BaseDendriteOptions = iota
DisableMetrics BaseDendriteOptions = iota
UseHTTPAPIs
PolylithMode
)
@ -107,12 +108,12 @@ const (
func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...BaseDendriteOptions) *BaseDendrite {
platformSanityChecks()
useHTTPAPIs := false
cacheMetrics := true
enableMetrics := true
isMonolith := true
for _, opt := range options {
switch opt {
case NoCacheMetrics:
cacheMetrics = false
case DisableMetrics:
enableMetrics = false
case UseHTTPAPIs:
useHTTPAPIs = true
case PolylithMode:
@ -160,7 +161,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base
}
}
cache, err := caching.NewInMemoryLRUCache(cacheMetrics)
cache, err := caching.NewInMemoryLRUCache(enableMetrics)
if err != nil {
logrus.WithError(err).Warnf("Failed to create cache")
}
@ -246,6 +247,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base
apiHttpClient: &apiClient,
Database: db, // set if monolith with global connection pool only
DatabaseWriter: writer, // set if monolith with global connection pool only
EnableMetrics: enableMetrics,
}
}

View file

@ -13,6 +13,7 @@ import (
"github.com/sirupsen/logrus"
natsserver "github.com/nats-io/nats-server/v2/server"
"github.com/nats-io/nats.go"
natsclient "github.com/nats-io/nats.go"
)
@ -21,6 +22,13 @@ type NATSInstance struct {
sync.Mutex
}
func DeleteAllStreams(js nats.JetStreamContext, cfg *config.JetStream) {
for _, stream := range streams { // streams are defined in streams.go
name := cfg.Prefixed(stream.Name)
_ = js.DeleteStream(name)
}
}
func (s *NATSInstance) Prepare(process *process.ProcessContext, cfg *config.JetStream) (natsclient.JetStreamContext, *natsclient.Conn) {
// check if we need an in-process NATS Server
if len(cfg.Addresses) != 0 {