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) { 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) {

View file

@ -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