Make monolith tests reliable with random keys

This commit is contained in:
Devon Hudson 2023-01-28 16:14:27 -07:00
parent e49ab5e321
commit 3cb9a96cdf
No known key found for this signature in database
GPG key ID: CD06B18E77F6A628
2 changed files with 37 additions and 14 deletions

View file

@ -600,20 +600,21 @@ func (m *DendriteMonolith) Start() {
}
}()
go func(ch <-chan pineconeEvents.Event) {
eLog := logrus.WithField("pinecone", "events")
stopRelayServerSync := make(chan bool)
stopRelayServerSync := make(chan bool)
m.relayRetriever = RelayServerRetriever{
Context: context.Background(),
ServerName: gomatrixserverlib.ServerName(m.PineconeRouter.PublicKey().String()),
FederationAPI: m.federationAPI,
relayServersQueried: make(map[gomatrixserverlib.ServerName]bool),
RelayAPI: monolith.RelayAPI,
running: *atomic.NewBool(false),
quit: stopRelayServerSync,
}
m.relayRetriever.InitializeRelayServers(eLog)
eLog := logrus.WithField("pinecone", "events")
m.relayRetriever = RelayServerRetriever{
Context: context.Background(),
ServerName: gomatrixserverlib.ServerName(m.PineconeRouter.PublicKey().String()),
FederationAPI: m.federationAPI,
relayServersQueried: make(map[gomatrixserverlib.ServerName]bool),
RelayAPI: monolith.RelayAPI,
running: *atomic.NewBool(false),
quit: stopRelayServerSync,
}
m.relayRetriever.InitializeRelayServers(eLog)
go func(ch <-chan pineconeEvents.Event) {
for event := range ch {
switch e := event.(type) {

View file

@ -18,6 +18,7 @@ import (
"context"
"fmt"
"net"
"strings"
"testing"
"time"
@ -247,12 +248,33 @@ func TestMonolithSetRelayServers(t *testing.T) {
relays := monolith.GetRelayServers(nodeID)
monolith.Stop()
if relays != expectedRelays {
if !containSameKeys(strings.Split(relays, ","), strings.Split(expectedRelays, ",")) {
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) {
testCases := []struct {
name string