refactor: update GMSL (#3058)

Sister PR to https://github.com/matrix-org/gomatrixserverlib/pull/364

Read this commit by commit to avoid going insane.
This commit is contained in:
kegsay 2023-04-19 15:50:33 +01:00 committed by GitHub
parent 9fa39263c0
commit 72285b2659
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
306 changed files with 2117 additions and 1934 deletions

View file

@ -24,6 +24,7 @@ import (
"github.com/matrix-org/gomatrix"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/gomatrixserverlib/spec"
"github.com/sirupsen/logrus"
"go.uber.org/atomic"
@ -51,11 +52,11 @@ type destinationQueue struct {
queues *OutgoingQueues
db storage.Database
process *process.ProcessContext
signing map[gomatrixserverlib.ServerName]*fclient.SigningIdentity
signing map[spec.ServerName]*fclient.SigningIdentity
rsAPI api.FederationRoomserverAPI
client fedapi.FederationClient // federation client
origin gomatrixserverlib.ServerName // origin of requests
destination gomatrixserverlib.ServerName // destination of requests
origin spec.ServerName // origin of requests
destination spec.ServerName // destination of requests
running atomic.Bool // is the queue worker running?
backingOff atomic.Bool // true if we're backing off
overflowed atomic.Bool // the queues exceed maxPDUsInMemory/maxEDUsInMemory, so we should consult the database for more
@ -426,7 +427,7 @@ func (oq *destinationQueue) nextTransaction(
relaySuccess := false
logrus.Infof("Sending %q to relay servers: %v", t.TransactionID, relayServers)
// TODO : how to pass through actual userID here?!?!?!?!
userID, userErr := gomatrixserverlib.NewUserID("@user:"+string(oq.destination), false)
userID, userErr := spec.NewUserID("@user:"+string(oq.destination), false)
if userErr != nil {
return userErr, sendMethod
}
@ -507,7 +508,7 @@ func (oq *destinationQueue) createTransaction(
// it so that we retry with the same transaction ID.
oq.transactionIDMutex.Lock()
if oq.transactionID == "" {
now := gomatrixserverlib.AsTimestamp(time.Now())
now := spec.AsTimestamp(time.Now())
oq.transactionID = gomatrixserverlib.TransactionID(fmt.Sprintf("%d-%d", now, oq.statistics.SuccessCount()))
}
oq.transactionIDMutex.Unlock()
@ -518,7 +519,7 @@ func (oq *destinationQueue) createTransaction(
}
t.Origin = oq.origin
t.Destination = oq.destination
t.OriginServerTS = gomatrixserverlib.AsTimestamp(time.Now())
t.OriginServerTS = spec.AsTimestamp(time.Now())
t.TransactionID = oq.transactionID
var pduReceipts []*receipt.Receipt

View file

@ -23,6 +23,7 @@ import (
"github.com/getsentry/sentry-go"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/gomatrixserverlib/spec"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
@ -43,12 +44,12 @@ type OutgoingQueues struct {
process *process.ProcessContext
disabled bool
rsAPI api.FederationRoomserverAPI
origin gomatrixserverlib.ServerName
origin spec.ServerName
client fedapi.FederationClient
statistics *statistics.Statistics
signing map[gomatrixserverlib.ServerName]*fclient.SigningIdentity
signing map[spec.ServerName]*fclient.SigningIdentity
queuesMutex sync.Mutex // protects the below
queues map[gomatrixserverlib.ServerName]*destinationQueue
queues map[spec.ServerName]*destinationQueue
}
func init() {
@ -87,7 +88,7 @@ func NewOutgoingQueues(
db storage.Database,
process *process.ProcessContext,
disabled bool,
origin gomatrixserverlib.ServerName,
origin spec.ServerName,
client fedapi.FederationClient,
rsAPI api.FederationRoomserverAPI,
statistics *statistics.Statistics,
@ -101,15 +102,15 @@ func NewOutgoingQueues(
origin: origin,
client: client,
statistics: statistics,
signing: map[gomatrixserverlib.ServerName]*fclient.SigningIdentity{},
queues: map[gomatrixserverlib.ServerName]*destinationQueue{},
signing: map[spec.ServerName]*fclient.SigningIdentity{},
queues: map[spec.ServerName]*destinationQueue{},
}
for _, identity := range signing {
queues.signing[identity.ServerName] = identity
}
// Look up which servers we have pending items for and then rehydrate those queues.
if !disabled {
serverNames := map[gomatrixserverlib.ServerName]struct{}{}
serverNames := map[spec.ServerName]struct{}{}
if names, err := db.GetPendingPDUServerNames(process.Context()); err == nil {
for _, serverName := range names {
serverNames[serverName] = struct{}{}
@ -148,7 +149,7 @@ type queuedEDU struct {
edu *gomatrixserverlib.EDU
}
func (oqs *OutgoingQueues) getQueue(destination gomatrixserverlib.ServerName) *destinationQueue {
func (oqs *OutgoingQueues) getQueue(destination spec.ServerName) *destinationQueue {
if oqs.statistics.ForServer(destination).Blacklisted() {
return nil
}
@ -187,8 +188,8 @@ func (oqs *OutgoingQueues) clearQueue(oq *destinationQueue) {
// SendEvent sends an event to the destinations
func (oqs *OutgoingQueues) SendEvent(
ev *gomatrixserverlib.HeaderedEvent, origin gomatrixserverlib.ServerName,
destinations []gomatrixserverlib.ServerName,
ev *gomatrixserverlib.HeaderedEvent, origin spec.ServerName,
destinations []spec.ServerName,
) error {
if oqs.disabled {
log.Trace("Federation is disabled, not sending event")
@ -203,7 +204,7 @@ func (oqs *OutgoingQueues) SendEvent(
// Deduplicate destinations and remove the origin from the list of
// destinations just to be sure.
destmap := map[gomatrixserverlib.ServerName]struct{}{}
destmap := map[spec.ServerName]struct{}{}
for _, d := range destinations {
destmap[d] = struct{}{}
}
@ -277,8 +278,8 @@ func (oqs *OutgoingQueues) SendEvent(
// SendEDU sends an EDU event to the destinations.
func (oqs *OutgoingQueues) SendEDU(
e *gomatrixserverlib.EDU, origin gomatrixserverlib.ServerName,
destinations []gomatrixserverlib.ServerName,
e *gomatrixserverlib.EDU, origin spec.ServerName,
destinations []spec.ServerName,
) error {
if oqs.disabled {
log.Trace("Federation is disabled, not sending EDU")
@ -293,7 +294,7 @@ func (oqs *OutgoingQueues) SendEDU(
// Deduplicate destinations and remove the origin from the list of
// destinations just to be sure.
destmap := map[gomatrixserverlib.ServerName]struct{}{}
destmap := map[spec.ServerName]struct{}{}
for _, d := range destinations {
destmap[d] = struct{}{}
}
@ -376,7 +377,7 @@ func (oqs *OutgoingQueues) SendEDU(
}
// RetryServer attempts to resend events to the given server if we had given up.
func (oqs *OutgoingQueues) RetryServer(srv gomatrixserverlib.ServerName, wasBlacklisted bool) {
func (oqs *OutgoingQueues) RetryServer(srv spec.ServerName, wasBlacklisted bool) {
if oqs.disabled {
return
}

View file

@ -25,6 +25,7 @@ import (
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/test/testrig"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/gomatrixserverlib/spec"
"go.uber.org/atomic"
"gotest.tools/v3/poll"
@ -91,7 +92,7 @@ func (f *stubFederationClient) SendTransaction(ctx context.Context, t gomatrixse
return fclient.RespSend{}, result
}
func (f *stubFederationClient) P2PSendTransactionToRelay(ctx context.Context, u gomatrixserverlib.UserID, t gomatrixserverlib.Transaction, forwardingServer gomatrixserverlib.ServerName) (res fclient.EmptyResp, err error) {
func (f *stubFederationClient) P2PSendTransactionToRelay(ctx context.Context, u spec.UserID, t gomatrixserverlib.Transaction, forwardingServer spec.ServerName) (res fclient.EmptyResp, err error) {
var result error
if !f.shouldTxRelaySucceed {
result = fmt.Errorf("relay transaction failed")
@ -113,7 +114,7 @@ func mustCreatePDU(t *testing.T) *gomatrixserverlib.HeaderedEvent {
func mustCreateEDU(t *testing.T) *gomatrixserverlib.EDU {
t.Helper()
return &gomatrixserverlib.EDU{Type: gomatrixserverlib.MTyping}
return &gomatrixserverlib.EDU{Type: spec.MTyping}
}
func testSetup(failuresUntilBlacklist uint32, failuresUntilAssumedOffline uint32, shouldTxSucceed bool, shouldTxRelaySucceed bool, t *testing.T, dbType test.DBType, realDatabase bool) (storage.Database, *stubFederationClient, *OutgoingQueues, *process.ProcessContext, func()) {
@ -143,7 +144,7 @@ func testSetup(failuresUntilBlacklist uint32, failuresUntilAssumedOffline uint32
func TestSendPDUOnSuccessRemovedFromDB(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(16)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, true, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -152,7 +153,7 @@ func TestSendPDUOnSuccessRemovedFromDB(t *testing.T) {
}()
ev := mustCreatePDU(t)
err := queues.SendEvent(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEvent(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -172,7 +173,7 @@ func TestSendPDUOnSuccessRemovedFromDB(t *testing.T) {
func TestSendEDUOnSuccessRemovedFromDB(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(16)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, true, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -181,7 +182,7 @@ func TestSendEDUOnSuccessRemovedFromDB(t *testing.T) {
}()
ev := mustCreateEDU(t)
err := queues.SendEDU(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEDU(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -201,7 +202,7 @@ func TestSendEDUOnSuccessRemovedFromDB(t *testing.T) {
func TestSendPDUOnFailStoredInDB(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(16)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, false, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -210,7 +211,7 @@ func TestSendPDUOnFailStoredInDB(t *testing.T) {
}()
ev := mustCreatePDU(t)
err := queues.SendEvent(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEvent(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -231,7 +232,7 @@ func TestSendPDUOnFailStoredInDB(t *testing.T) {
func TestSendEDUOnFailStoredInDB(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(16)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, false, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -240,7 +241,7 @@ func TestSendEDUOnFailStoredInDB(t *testing.T) {
}()
ev := mustCreateEDU(t)
err := queues.SendEDU(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEDU(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -261,7 +262,7 @@ func TestSendEDUOnFailStoredInDB(t *testing.T) {
func TestSendPDUAgainDoesntInterruptBackoff(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(16)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, false, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -270,7 +271,7 @@ func TestSendPDUAgainDoesntInterruptBackoff(t *testing.T) {
}()
ev := mustCreatePDU(t)
err := queues.SendEvent(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEvent(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -289,7 +290,7 @@ func TestSendPDUAgainDoesntInterruptBackoff(t *testing.T) {
fc.shouldTxSucceed = true
ev = mustCreatePDU(t)
err = queues.SendEvent(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err = queues.SendEvent(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
pollEnd := time.Now().Add(1 * time.Second)
@ -312,7 +313,7 @@ func TestSendPDUAgainDoesntInterruptBackoff(t *testing.T) {
func TestSendEDUAgainDoesntInterruptBackoff(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(16)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, false, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -321,7 +322,7 @@ func TestSendEDUAgainDoesntInterruptBackoff(t *testing.T) {
}()
ev := mustCreateEDU(t)
err := queues.SendEDU(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEDU(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -340,7 +341,7 @@ func TestSendEDUAgainDoesntInterruptBackoff(t *testing.T) {
fc.shouldTxSucceed = true
ev = mustCreateEDU(t)
err = queues.SendEDU(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err = queues.SendEDU(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
pollEnd := time.Now().Add(1 * time.Second)
@ -363,7 +364,7 @@ func TestSendEDUAgainDoesntInterruptBackoff(t *testing.T) {
func TestSendPDUMultipleFailuresBlacklisted(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(2)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, false, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -372,7 +373,7 @@ func TestSendPDUMultipleFailuresBlacklisted(t *testing.T) {
}()
ev := mustCreatePDU(t)
err := queues.SendEvent(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEvent(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -395,7 +396,7 @@ func TestSendPDUMultipleFailuresBlacklisted(t *testing.T) {
func TestSendEDUMultipleFailuresBlacklisted(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(2)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, false, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -404,7 +405,7 @@ func TestSendEDUMultipleFailuresBlacklisted(t *testing.T) {
}()
ev := mustCreateEDU(t)
err := queues.SendEDU(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEDU(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -427,7 +428,7 @@ func TestSendEDUMultipleFailuresBlacklisted(t *testing.T) {
func TestSendPDUBlacklistedWithPriorExternalFailure(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(2)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, false, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -438,7 +439,7 @@ func TestSendPDUBlacklistedWithPriorExternalFailure(t *testing.T) {
queues.statistics.ForServer(destination).Failure()
ev := mustCreatePDU(t)
err := queues.SendEvent(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEvent(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -461,7 +462,7 @@ func TestSendPDUBlacklistedWithPriorExternalFailure(t *testing.T) {
func TestSendEDUBlacklistedWithPriorExternalFailure(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(2)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, false, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -472,7 +473,7 @@ func TestSendEDUBlacklistedWithPriorExternalFailure(t *testing.T) {
queues.statistics.ForServer(destination).Failure()
ev := mustCreateEDU(t)
err := queues.SendEDU(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEDU(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -495,7 +496,7 @@ func TestSendEDUBlacklistedWithPriorExternalFailure(t *testing.T) {
func TestRetryServerSendsPDUSuccessfully(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(1)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, false, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -507,7 +508,7 @@ func TestRetryServerSendsPDUSuccessfully(t *testing.T) {
// before it is blacklisted and deleted.
dest := queues.getQueue(destination)
ev := mustCreatePDU(t)
err := queues.SendEvent(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEvent(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
checkBlacklisted := func(log poll.LogT) poll.Result {
@ -546,7 +547,7 @@ func TestRetryServerSendsPDUSuccessfully(t *testing.T) {
func TestRetryServerSendsEDUSuccessfully(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(1)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, false, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -558,7 +559,7 @@ func TestRetryServerSendsEDUSuccessfully(t *testing.T) {
// before it is blacklisted and deleted.
dest := queues.getQueue(destination)
ev := mustCreateEDU(t)
err := queues.SendEDU(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEDU(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
checkBlacklisted := func(log poll.LogT) poll.Result {
@ -597,7 +598,7 @@ func TestRetryServerSendsEDUSuccessfully(t *testing.T) {
func TestSendPDUBatches(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(16)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
// test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
// db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, true, t, dbType, true)
@ -608,7 +609,7 @@ func TestSendPDUBatches(t *testing.T) {
<-pc.WaitForShutdown()
}()
destinations := map[gomatrixserverlib.ServerName]struct{}{destination: {}}
destinations := map[spec.ServerName]struct{}{destination: {}}
// Populate database with > maxPDUsPerTransaction
pduMultiplier := uint32(3)
for i := 0; i < maxPDUsPerTransaction*int(pduMultiplier); i++ {
@ -620,7 +621,7 @@ func TestSendPDUBatches(t *testing.T) {
}
ev := mustCreatePDU(t)
err := queues.SendEvent(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEvent(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -641,7 +642,7 @@ func TestSendPDUBatches(t *testing.T) {
func TestSendEDUBatches(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(16)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
// test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
// db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, true, t, dbType, true)
@ -652,7 +653,7 @@ func TestSendEDUBatches(t *testing.T) {
<-pc.WaitForShutdown()
}()
destinations := map[gomatrixserverlib.ServerName]struct{}{destination: {}}
destinations := map[spec.ServerName]struct{}{destination: {}}
// Populate database with > maxEDUsPerTransaction
eduMultiplier := uint32(3)
for i := 0; i < maxEDUsPerTransaction*int(eduMultiplier); i++ {
@ -664,7 +665,7 @@ func TestSendEDUBatches(t *testing.T) {
}
ev := mustCreateEDU(t)
err := queues.SendEDU(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEDU(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -685,7 +686,7 @@ func TestSendEDUBatches(t *testing.T) {
func TestSendPDUAndEDUBatches(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(16)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
// test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
// db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, true, t, dbType, true)
@ -696,7 +697,7 @@ func TestSendPDUAndEDUBatches(t *testing.T) {
<-pc.WaitForShutdown()
}()
destinations := map[gomatrixserverlib.ServerName]struct{}{destination: {}}
destinations := map[spec.ServerName]struct{}{destination: {}}
// Populate database with > maxEDUsPerTransaction
multiplier := uint32(3)
for i := 0; i < maxPDUsPerTransaction*int(multiplier)+1; i++ {
@ -716,7 +717,7 @@ func TestSendPDUAndEDUBatches(t *testing.T) {
}
ev := mustCreateEDU(t)
err := queues.SendEDU(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEDU(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -739,7 +740,7 @@ func TestSendPDUAndEDUBatches(t *testing.T) {
func TestExternalFailureBackoffDoesntStartQueue(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(16)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, true, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -749,7 +750,7 @@ func TestExternalFailureBackoffDoesntStartQueue(t *testing.T) {
dest := queues.getQueue(destination)
queues.statistics.ForServer(destination).Failure()
destinations := map[gomatrixserverlib.ServerName]struct{}{destination: {}}
destinations := map[spec.ServerName]struct{}{destination: {}}
ev := mustCreatePDU(t)
headeredJSON, _ := json.Marshal(ev)
nid, _ := db.StoreJSON(pc.Context(), string(headeredJSON))
@ -775,8 +776,8 @@ func TestQueueInteractsWithRealDatabasePDUAndEDU(t *testing.T) {
// NOTE : Only one test case against real databases can be run at a time.
t.Parallel()
failuresUntilBlacklist := uint32(1)
destination := gomatrixserverlib.ServerName("remotehost")
destinations := map[gomatrixserverlib.ServerName]struct{}{destination: {}}
destination := spec.ServerName("remotehost")
destinations := map[spec.ServerName]struct{}{destination: {}}
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilBlacklist+1, false, false, t, dbType, true)
// NOTE : These defers aren't called if go test is killed so the dbs may not get cleaned up.
@ -790,7 +791,7 @@ func TestQueueInteractsWithRealDatabasePDUAndEDU(t *testing.T) {
// before it is blacklisted and deleted.
dest := queues.getQueue(destination)
ev := mustCreatePDU(t)
err := queues.SendEvent(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEvent(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
// NOTE : The server can be blacklisted before this, so manually inject the event
@ -843,7 +844,7 @@ func TestSendPDUMultipleFailuresAssumedOffline(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(7)
failuresUntilAssumedOffline := uint32(2)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilAssumedOffline, false, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -852,7 +853,7 @@ func TestSendPDUMultipleFailuresAssumedOffline(t *testing.T) {
}()
ev := mustCreatePDU(t)
err := queues.SendEvent(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEvent(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -876,7 +877,7 @@ func TestSendEDUMultipleFailuresAssumedOffline(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(7)
failuresUntilAssumedOffline := uint32(2)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilAssumedOffline, false, false, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -885,7 +886,7 @@ func TestSendEDUMultipleFailuresAssumedOffline(t *testing.T) {
}()
ev := mustCreateEDU(t)
err := queues.SendEDU(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEDU(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -909,7 +910,7 @@ func TestSendPDUOnRelaySuccessRemovedFromDB(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(16)
failuresUntilAssumedOffline := uint32(1)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilAssumedOffline, false, true, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -917,11 +918,11 @@ func TestSendPDUOnRelaySuccessRemovedFromDB(t *testing.T) {
<-pc.WaitForShutdown()
}()
relayServers := []gomatrixserverlib.ServerName{"relayserver"}
relayServers := []spec.ServerName{"relayserver"}
queues.statistics.ForServer(destination).AddRelayServers(relayServers)
ev := mustCreatePDU(t)
err := queues.SendEvent(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEvent(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {
@ -948,7 +949,7 @@ func TestSendEDUOnRelaySuccessRemovedFromDB(t *testing.T) {
t.Parallel()
failuresUntilBlacklist := uint32(16)
failuresUntilAssumedOffline := uint32(1)
destination := gomatrixserverlib.ServerName("remotehost")
destination := spec.ServerName("remotehost")
db, fc, queues, pc, close := testSetup(failuresUntilBlacklist, failuresUntilAssumedOffline, false, true, t, test.DBTypeSQLite, false)
defer close()
defer func() {
@ -956,11 +957,11 @@ func TestSendEDUOnRelaySuccessRemovedFromDB(t *testing.T) {
<-pc.WaitForShutdown()
}()
relayServers := []gomatrixserverlib.ServerName{"relayserver"}
relayServers := []spec.ServerName{"relayserver"}
queues.statistics.ForServer(destination).AddRelayServers(relayServers)
ev := mustCreateEDU(t)
err := queues.SendEDU(ev, "localhost", []gomatrixserverlib.ServerName{destination})
err := queues.SendEDU(ev, "localhost", []spec.ServerName{destination})
assert.NoError(t, err)
check := func(log poll.LogT) poll.Result {