aboutsummaryrefslogtreecommitdiff
path: root/setup
diff options
context:
space:
mode:
authorkegsay <kegan@matrix.org>2022-05-09 17:23:02 +0100
committerGitHub <noreply@github.com>2022-05-09 17:23:02 +0100
commit236b16aa6c97bc0894388dce7f6b420ef7a1fd88 (patch)
tree9b9879b068eb45541730da203d75fed0631800d1 /setup
parenta443d1e5f3796942f68067741f4bdd482548bfd7 (diff)
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
Diffstat (limited to 'setup')
-rw-r--r--setup/base/base.go12
-rw-r--r--setup/jetstream/nats.go8
2 files changed, 15 insertions, 5 deletions
diff --git a/setup/base/base.go b/setup/base/base.go
index 0e7528a0..5cbd7da9 100644
--- a/setup/base/base.go
+++ b/setup/base/base.go
@@ -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,
}
}
diff --git a/setup/jetstream/nats.go b/setup/jetstream/nats.go
index 426f02bb..248b0e65 100644
--- a/setup/jetstream/nats.go
+++ b/setup/jetstream/nats.go
@@ -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 {