mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-15 21:52:25 +03:00
Initial Store & Forward Implementation (#2917)
This adds store & forward relays into dendrite for p2p. A few things have changed: - new relay api serves new http endpoints for s&f federation - updated outbound federation queueing which will attempt to forward using s&f if appropriate - database entries to track s&f relays for other nodes
This commit is contained in:
parent
48fa869fa3
commit
5b73592f5a
77 changed files with 7646 additions and 1373 deletions
|
@ -4,17 +4,26 @@ import (
|
|||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/test"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const (
|
||||
FailuresUntilAssumedOffline = 3
|
||||
FailuresUntilBlacklist = 8
|
||||
)
|
||||
|
||||
func TestBackoff(t *testing.T) {
|
||||
stats := NewStatistics(nil, 7)
|
||||
stats := NewStatistics(nil, FailuresUntilBlacklist, FailuresUntilAssumedOffline)
|
||||
server := ServerStatistics{
|
||||
statistics: &stats,
|
||||
serverName: "test.com",
|
||||
}
|
||||
|
||||
// Start by checking that counting successes works.
|
||||
server.Success()
|
||||
server.Success(SendDirect)
|
||||
if successes := server.SuccessCount(); successes != 1 {
|
||||
t.Fatalf("Expected success count 1, got %d", successes)
|
||||
}
|
||||
|
@ -31,9 +40,8 @@ func TestBackoff(t *testing.T) {
|
|||
// side effects since a backoff is already in progress. If it does
|
||||
// then we'll fail.
|
||||
until, blacklisted := server.Failure()
|
||||
|
||||
// Get the duration.
|
||||
_, blacklist := server.BackoffInfo()
|
||||
blacklist := server.Blacklisted()
|
||||
assumedOffline := server.AssumedOffline()
|
||||
duration := time.Until(until)
|
||||
|
||||
// Unset the backoff, or otherwise our next call will think that
|
||||
|
@ -41,16 +49,43 @@ func TestBackoff(t *testing.T) {
|
|||
server.cancel()
|
||||
server.backoffStarted.Store(false)
|
||||
|
||||
if i >= stats.FailuresUntilAssumedOffline {
|
||||
if !assumedOffline {
|
||||
t.Fatalf("Backoff %d should have resulted in assuming the destination was offline but didn't", i)
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we should be assumed offline by now.
|
||||
if i >= stats.FailuresUntilAssumedOffline {
|
||||
if !assumedOffline {
|
||||
t.Fatalf("Backoff %d should have resulted in assumed offline but didn't", i)
|
||||
} else {
|
||||
t.Logf("Backoff %d is assumed offline as expected", i)
|
||||
}
|
||||
} else {
|
||||
if assumedOffline {
|
||||
t.Fatalf("Backoff %d should not have resulted in assumed offline but did", i)
|
||||
} else {
|
||||
t.Logf("Backoff %d is not assumed offline as expected", i)
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we should be blacklisted by now.
|
||||
if i >= stats.FailuresUntilBlacklist {
|
||||
if !blacklist {
|
||||
t.Fatalf("Backoff %d should have resulted in blacklist but didn't", i)
|
||||
} else if blacklist != blacklisted {
|
||||
t.Fatalf("BackoffInfo and Failure returned different blacklist values")
|
||||
t.Fatalf("Blacklisted and Failure returned different blacklist values")
|
||||
} else {
|
||||
t.Logf("Backoff %d is blacklisted as expected", i)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if blacklist {
|
||||
t.Fatalf("Backoff %d should not have resulted in blacklist but did", i)
|
||||
} else {
|
||||
t.Logf("Backoff %d is not blacklisted as expected", i)
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the duration is what we expect.
|
||||
|
@ -69,3 +104,14 @@ func TestBackoff(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRelayServersListing(t *testing.T) {
|
||||
stats := NewStatistics(test.NewInMemoryFederationDatabase(), FailuresUntilBlacklist, FailuresUntilAssumedOffline)
|
||||
server := ServerStatistics{statistics: &stats}
|
||||
server.AddRelayServers([]gomatrixserverlib.ServerName{"relay1", "relay1", "relay2"})
|
||||
relayServers := server.KnownRelayServers()
|
||||
assert.Equal(t, []gomatrixserverlib.ServerName{"relay1", "relay2"}, relayServers)
|
||||
server.AddRelayServers([]gomatrixserverlib.ServerName{"relay1", "relay1", "relay2"})
|
||||
relayServers = server.KnownRelayServers()
|
||||
assert.Equal(t, []gomatrixserverlib.ServerName{"relay1", "relay2"}, relayServers)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue