fix remaining broken tests relying on worker queue logic
This commit is contained in:
parent
529715f39f
commit
1f9a077c7b
|
@ -19,6 +19,7 @@ package federatingdb_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/superseriousbusiness/activity/streams/vocab"
|
"github.com/superseriousbusiness/activity/streams/vocab"
|
||||||
|
@ -42,7 +43,7 @@ func (suite *AnnounceTestSuite) TestNewAnnounce() {
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// should be a message heading to the processor now, which we can intercept here
|
// should be a message heading to the processor now, which we can intercept here
|
||||||
msg := <-suite.fromFederator
|
msg, _ := suite.getFederatorMsg(5 * time.Second)
|
||||||
suite.Equal(ap.ActivityAnnounce, msg.APObjectType)
|
suite.Equal(ap.ActivityAnnounce, msg.APObjectType)
|
||||||
suite.Equal(ap.ActivityCreate, msg.APActivityType)
|
suite.Equal(ap.ActivityCreate, msg.APActivityType)
|
||||||
|
|
||||||
|
@ -69,7 +70,7 @@ func (suite *AnnounceTestSuite) TestAnnounceTwice() {
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// should be a message heading to the processor now, which we can intercept here
|
// should be a message heading to the processor now, which we can intercept here
|
||||||
msg := <-suite.fromFederator
|
msg, _ := suite.getFederatorMsg(5 * time.Second)
|
||||||
suite.Equal(ap.ActivityAnnounce, msg.APObjectType)
|
suite.Equal(ap.ActivityAnnounce, msg.APObjectType)
|
||||||
suite.Equal(ap.ActivityCreate, msg.APActivityType)
|
suite.Equal(ap.ActivityCreate, msg.APActivityType)
|
||||||
boost, ok := msg.GTSModel.(*gtsmodel.Status)
|
boost, ok := msg.GTSModel.(*gtsmodel.Status)
|
||||||
|
@ -94,7 +95,8 @@ func (suite *AnnounceTestSuite) TestAnnounceTwice() {
|
||||||
|
|
||||||
// since this is a repeat announce with the same URI, just delivered to a different inbox,
|
// since this is a repeat announce with the same URI, just delivered to a different inbox,
|
||||||
// we should have nothing in the messages channel...
|
// we should have nothing in the messages channel...
|
||||||
suite.Empty(suite.fromFederator)
|
_, ok = suite.getFederatorMsg(time.Second)
|
||||||
|
suite.False(ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAnnounceTestSuite(t *testing.T) {
|
func TestAnnounceTestSuite(t *testing.T) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/superseriousbusiness/activity/streams"
|
"github.com/superseriousbusiness/activity/streams"
|
||||||
|
@ -48,7 +49,7 @@ func (suite *CreateTestSuite) TestCreateNote() {
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// should be a message heading to the processor now, which we can intercept here
|
// should be a message heading to the processor now, which we can intercept here
|
||||||
msg := <-suite.fromFederator
|
msg, _ := suite.getFederatorMsg(5 * time.Second)
|
||||||
suite.Equal(ap.ObjectNote, msg.APObjectType)
|
suite.Equal(ap.ObjectNote, msg.APObjectType)
|
||||||
suite.Equal(ap.ActivityCreate, msg.APActivityType)
|
suite.Equal(ap.ActivityCreate, msg.APActivityType)
|
||||||
suite.Equal(note, msg.APObject)
|
suite.Equal(note, msg.APObject)
|
||||||
|
|
|
@ -19,6 +19,7 @@ package federatingdb_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||||
|
@ -36,7 +37,6 @@ type FederatingDBTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
db db.DB
|
db db.DB
|
||||||
tc *typeutils.Converter
|
tc *typeutils.Converter
|
||||||
fromFederator chan messages.FromFediAPI
|
|
||||||
federatingDB federatingdb.DB
|
federatingDB federatingdb.DB
|
||||||
state state.State
|
state state.State
|
||||||
|
|
||||||
|
@ -51,6 +51,13 @@ type FederatingDBTestSuite struct {
|
||||||
testActivities map[string]testrig.ActivityWithSignature
|
testActivities map[string]testrig.ActivityWithSignature
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *FederatingDBTestSuite) getFederatorMsg(timeout time.Duration) (*messages.FromFediAPI, bool) {
|
||||||
|
ctx := context.Background()
|
||||||
|
ctx, cncl := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cncl()
|
||||||
|
return suite.state.Workers.Federator.Queue.PopCtx(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *FederatingDBTestSuite) SetupSuite() {
|
func (suite *FederatingDBTestSuite) SetupSuite() {
|
||||||
suite.testTokens = testrig.NewTestTokens()
|
suite.testTokens = testrig.NewTestTokens()
|
||||||
suite.testClients = testrig.NewTestClients()
|
suite.testClients = testrig.NewTestClients()
|
||||||
|
@ -69,8 +76,6 @@ func (suite *FederatingDBTestSuite) SetupTest() {
|
||||||
suite.state.Caches.Init()
|
suite.state.Caches.Init()
|
||||||
testrig.StartNoopWorkers(&suite.state)
|
testrig.StartNoopWorkers(&suite.state)
|
||||||
|
|
||||||
suite.fromFederator = make(chan messages.FromFediAPI, 10)
|
|
||||||
|
|
||||||
suite.db = testrig.NewTestDB(&suite.state)
|
suite.db = testrig.NewTestDB(&suite.state)
|
||||||
|
|
||||||
suite.testActivities = testrig.NewTestActivities(suite.testAccounts)
|
suite.testActivities = testrig.NewTestActivities(suite.testAccounts)
|
||||||
|
@ -91,13 +96,6 @@ func (suite *FederatingDBTestSuite) SetupTest() {
|
||||||
func (suite *FederatingDBTestSuite) TearDownTest() {
|
func (suite *FederatingDBTestSuite) TearDownTest() {
|
||||||
testrig.StandardDBTeardown(suite.db)
|
testrig.StandardDBTeardown(suite.db)
|
||||||
testrig.StopWorkers(&suite.state)
|
testrig.StopWorkers(&suite.state)
|
||||||
for suite.fromFederator != nil {
|
|
||||||
select {
|
|
||||||
case <-suite.fromFederator:
|
|
||||||
default:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestContext(receivingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account) context.Context {
|
func createTestContext(receivingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account) context.Context {
|
||||||
|
|
|
@ -27,7 +27,6 @@ import (
|
||||||
"github.com/superseriousbusiness/activity/streams/vocab"
|
"github.com/superseriousbusiness/activity/streams/vocab"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MoveTestSuite struct {
|
type MoveTestSuite struct {
|
||||||
|
@ -78,13 +77,7 @@ func (suite *MoveTestSuite) TestMove() {
|
||||||
suite.move(receivingAcct, requestingAcct, moveStr1)
|
suite.move(receivingAcct, requestingAcct, moveStr1)
|
||||||
|
|
||||||
// Should be a message heading to the processor.
|
// Should be a message heading to the processor.
|
||||||
var msg messages.FromFediAPI
|
msg, _ := suite.getFederatorMsg(5 * time.Second)
|
||||||
select {
|
|
||||||
case msg = <-suite.fromFederator:
|
|
||||||
// Fine.
|
|
||||||
case <-time.After(5 * time.Second):
|
|
||||||
suite.FailNow("", "timeout waiting for suite.fromFederator")
|
|
||||||
}
|
|
||||||
suite.Equal(ap.ObjectProfile, msg.APObjectType)
|
suite.Equal(ap.ObjectProfile, msg.APObjectType)
|
||||||
suite.Equal(ap.ActivityMove, msg.APActivityType)
|
suite.Equal(ap.ActivityMove, msg.APActivityType)
|
||||||
|
|
||||||
|
@ -101,12 +94,7 @@ func (suite *MoveTestSuite) TestMove() {
|
||||||
|
|
||||||
// Should be a message heading to the processor
|
// Should be a message heading to the processor
|
||||||
// since this is just a straight up retry.
|
// since this is just a straight up retry.
|
||||||
select {
|
msg, _ = suite.getFederatorMsg(5 * time.Second)
|
||||||
case msg = <-suite.fromFederator:
|
|
||||||
// Fine.
|
|
||||||
case <-time.After(5 * time.Second):
|
|
||||||
suite.FailNow("", "timeout waiting for suite.fromFederator")
|
|
||||||
}
|
|
||||||
suite.Equal(ap.ObjectProfile, msg.APObjectType)
|
suite.Equal(ap.ObjectProfile, msg.APObjectType)
|
||||||
suite.Equal(ap.ActivityMove, msg.APActivityType)
|
suite.Equal(ap.ActivityMove, msg.APActivityType)
|
||||||
|
|
||||||
|
@ -126,12 +114,7 @@ func (suite *MoveTestSuite) TestMove() {
|
||||||
|
|
||||||
// Should be a message heading to the processor
|
// Should be a message heading to the processor
|
||||||
// since this is just a retry with a different ID.
|
// since this is just a retry with a different ID.
|
||||||
select {
|
msg, _ = suite.getFederatorMsg(5 * time.Second)
|
||||||
case msg = <-suite.fromFederator:
|
|
||||||
// Fine.
|
|
||||||
case <-time.After(5 * time.Second):
|
|
||||||
suite.FailNow("", "timeout waiting for suite.fromFederator")
|
|
||||||
}
|
|
||||||
suite.Equal(ap.ObjectProfile, msg.APObjectType)
|
suite.Equal(ap.ObjectProfile, msg.APObjectType)
|
||||||
suite.Equal(ap.ActivityMove, msg.APActivityType)
|
suite.Equal(ap.ActivityMove, msg.APActivityType)
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,8 @@ func (suite *RejectTestSuite) TestRejectFollowRequest() {
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// there should be nothing in the federator channel since nothing needs to be passed
|
// there should be nothing in the federator channel since nothing needs to be passed
|
||||||
suite.Empty(suite.fromFederator)
|
_, ok := suite.getFederatorMsg(time.Second)
|
||||||
|
suite.False(ok)
|
||||||
|
|
||||||
// the follow request should not be in the database anymore -- it's been rejected
|
// the follow request should not be in the database anymore -- it's been rejected
|
||||||
err = suite.db.GetByID(ctx, fr.ID, >smodel.FollowRequest{})
|
err = suite.db.GetByID(ctx, fr.ID, >smodel.FollowRequest{})
|
||||||
|
|
Loading…
Reference in New Issue