mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 03:03:10 -06:00
Add jetstream.PrepareForTests
This commit is contained in:
parent
c828f01aaa
commit
d62f52a1bc
|
|
@ -2,6 +2,7 @@ package input_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -10,11 +11,25 @@ import (
|
||||||
"github.com/matrix-org/dendrite/roomserver/internal/input"
|
"github.com/matrix-org/dendrite/roomserver/internal/input"
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||||
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/nats-io/nats.go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var js nats.JetStreamContext
|
||||||
|
var jc *nats.Conn
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
var pc *process.ProcessContext
|
||||||
|
pc, js, jc = jetstream.PrepareForTests()
|
||||||
|
code := m.Run()
|
||||||
|
pc.ShutdownDendrite()
|
||||||
|
pc.WaitForComponentsToFinish()
|
||||||
|
os.Exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
func TestSingleTransactionOnInput(t *testing.T) {
|
func TestSingleTransactionOnInput(t *testing.T) {
|
||||||
t.SkipNow() // this doesn't work even with postgres enabled due to nats client not being set and you can't easily make one.
|
|
||||||
deadline, _ := t.Deadline()
|
deadline, _ := t.Deadline()
|
||||||
if max := time.Now().Add(time.Second * 3); deadline.After(max) {
|
if max := time.Now().Add(time.Second * 3); deadline.After(max) {
|
||||||
deadline = max
|
deadline = max
|
||||||
|
|
@ -50,7 +65,9 @@ func TestSingleTransactionOnInput(t *testing.T) {
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
}
|
}
|
||||||
inputter := &input.Inputer{
|
inputter := &input.Inputer{
|
||||||
DB: db,
|
DB: db,
|
||||||
|
JetStream: js,
|
||||||
|
NATSClient: jc,
|
||||||
}
|
}
|
||||||
res := &api.InputRoomEventsResponse{}
|
res := &api.InputRoomEventsResponse{}
|
||||||
inputter.InputRoomEvents(
|
inputter.InputRoomEvents(
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,22 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
natsserver "github.com/nats-io/nats-server/v2/server"
|
natsserver "github.com/nats-io/nats-server/v2/server"
|
||||||
|
"github.com/nats-io/nats.go"
|
||||||
natsclient "github.com/nats-io/nats.go"
|
natsclient "github.com/nats-io/nats.go"
|
||||||
)
|
)
|
||||||
|
|
||||||
var natsServer *natsserver.Server
|
var natsServer *natsserver.Server
|
||||||
var natsServerMutex sync.Mutex
|
var natsServerMutex sync.Mutex
|
||||||
|
|
||||||
|
func PrepareForTests() (*process.ProcessContext, nats.JetStreamContext, *nats.Conn) {
|
||||||
|
cfg := &config.Dendrite{}
|
||||||
|
cfg.Defaults(true)
|
||||||
|
cfg.Global.JetStream.InMemory = true
|
||||||
|
pc := process.NewProcessContext()
|
||||||
|
js, jc := Prepare(pc, &cfg.Global.JetStream)
|
||||||
|
return pc, js, jc
|
||||||
|
}
|
||||||
|
|
||||||
func Prepare(process *process.ProcessContext, cfg *config.JetStream) (natsclient.JetStreamContext, *natsclient.Conn) {
|
func Prepare(process *process.ProcessContext, cfg *config.JetStream) (natsclient.JetStreamContext, *natsclient.Conn) {
|
||||||
// check if we need an in-process NATS Server
|
// check if we need an in-process NATS Server
|
||||||
if len(cfg.Addresses) != 0 {
|
if len(cfg.Addresses) != 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue