mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-20 12:33:09 -06:00
Make monolith tests reliable with random keys
This commit is contained in:
parent
e49ab5e321
commit
3cb9a96cdf
|
|
@ -600,20 +600,21 @@ func (m *DendriteMonolith) Start() {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func(ch <-chan pineconeEvents.Event) {
|
stopRelayServerSync := make(chan bool)
|
||||||
eLog := logrus.WithField("pinecone", "events")
|
|
||||||
stopRelayServerSync := make(chan bool)
|
|
||||||
|
|
||||||
m.relayRetriever = RelayServerRetriever{
|
eLog := logrus.WithField("pinecone", "events")
|
||||||
Context: context.Background(),
|
m.relayRetriever = RelayServerRetriever{
|
||||||
ServerName: gomatrixserverlib.ServerName(m.PineconeRouter.PublicKey().String()),
|
Context: context.Background(),
|
||||||
FederationAPI: m.federationAPI,
|
ServerName: gomatrixserverlib.ServerName(m.PineconeRouter.PublicKey().String()),
|
||||||
relayServersQueried: make(map[gomatrixserverlib.ServerName]bool),
|
FederationAPI: m.federationAPI,
|
||||||
RelayAPI: monolith.RelayAPI,
|
relayServersQueried: make(map[gomatrixserverlib.ServerName]bool),
|
||||||
running: *atomic.NewBool(false),
|
RelayAPI: monolith.RelayAPI,
|
||||||
quit: stopRelayServerSync,
|
running: *atomic.NewBool(false),
|
||||||
}
|
quit: stopRelayServerSync,
|
||||||
m.relayRetriever.InitializeRelayServers(eLog)
|
}
|
||||||
|
m.relayRetriever.InitializeRelayServers(eLog)
|
||||||
|
|
||||||
|
go func(ch <-chan pineconeEvents.Event) {
|
||||||
|
|
||||||
for event := range ch {
|
for event := range ch {
|
||||||
switch e := event.(type) {
|
switch e := event.(type) {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -247,12 +248,33 @@ func TestMonolithSetRelayServers(t *testing.T) {
|
||||||
relays := monolith.GetRelayServers(nodeID)
|
relays := monolith.GetRelayServers(nodeID)
|
||||||
monolith.Stop()
|
monolith.Stop()
|
||||||
|
|
||||||
if relays != expectedRelays {
|
if !containSameKeys(strings.Split(relays, ","), strings.Split(expectedRelays, ",")) {
|
||||||
t.Fatalf("%s: expected %s got %s", tc.name, expectedRelays, relays)
|
t.Fatalf("%s: expected %s got %s", tc.name, expectedRelays, relays)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func containSameKeys(expected []string, actual []string) bool {
|
||||||
|
if len(expected) != len(actual) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, expectedKey := range expected {
|
||||||
|
hasMatch := false
|
||||||
|
for _, actualKey := range actual {
|
||||||
|
if actualKey == expectedKey {
|
||||||
|
hasMatch = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !hasMatch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseServerKey(t *testing.T) {
|
func TestParseServerKey(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue