chore: disable curated communities loop in tests (#4894)
This commit is contained in:
parent
6522d52016
commit
c8044bf400
|
@ -0,0 +1,11 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
type CodeControlFlags struct {
|
||||||
|
// AutoRequestHistoricMessages indicates whether we should automatically request
|
||||||
|
// historic messages on getting online, connecting to store node, etc.
|
||||||
|
AutoRequestHistoricMessages bool
|
||||||
|
|
||||||
|
// CuratedCommunitiesUpdateLoopEnabled indicates whether we should disable the curated communities update loop.
|
||||||
|
// Usually should be disabled in tests.
|
||||||
|
CuratedCommunitiesUpdateLoopEnabled bool
|
||||||
|
}
|
|
@ -26,8 +26,4 @@ type FeatureFlags struct {
|
||||||
|
|
||||||
// Peersyncing indicates whether we should advertise and sync messages with other peers
|
// Peersyncing indicates whether we should advertise and sync messages with other peers
|
||||||
Peersyncing bool
|
Peersyncing bool
|
||||||
|
|
||||||
// AutoRequestHistoricMessages indicates whether we should automatically request
|
|
||||||
// historic messages on getting online, connecting to store node, etc.
|
|
||||||
AutoRequestHistoricMessages bool
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
hexutil "github.com/ethereum/go-ethereum/common/hexutil"
|
hexutil "github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
|
||||||
"github.com/status-im/status-go/account"
|
"github.com/status-im/status-go/account"
|
||||||
"github.com/status-im/status-go/appdatabase"
|
|
||||||
"github.com/status-im/status-go/eth-node/crypto"
|
"github.com/status-im/status-go/eth-node/crypto"
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||||
|
@ -26,9 +25,7 @@ import (
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
"github.com/status-im/status-go/protocol/requests"
|
"github.com/status-im/status-go/protocol/requests"
|
||||||
"github.com/status-im/status-go/services/communitytokens"
|
"github.com/status-im/status-go/services/communitytokens"
|
||||||
mailserversDB "github.com/status-im/status-go/services/mailservers"
|
|
||||||
walletToken "github.com/status-im/status-go/services/wallet/token"
|
walletToken "github.com/status-im/status-go/services/wallet/token"
|
||||||
"github.com/status-im/status-go/t/helpers"
|
|
||||||
"github.com/status-im/status-go/transactions"
|
"github.com/status-im/status-go/transactions"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -590,25 +587,3 @@ func waitOnCommunitiesEvent(user *Messenger, condition func(*communities.Subscri
|
||||||
|
|
||||||
return errCh
|
return errCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithTestStoreNode(s *suite.Suite, id string, address string, fleet string, collectiblesServiceMock *CollectiblesServiceMock) Option {
|
|
||||||
return func(c *config) error {
|
|
||||||
sqldb, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
db := mailserversDB.NewDB(sqldb)
|
|
||||||
err = db.Add(mailserversDB.Mailserver{
|
|
||||||
ID: id,
|
|
||||||
Name: id,
|
|
||||||
Address: address,
|
|
||||||
Fleet: fleet,
|
|
||||||
})
|
|
||||||
s.Require().NoError(err)
|
|
||||||
|
|
||||||
c.mailserversDatabase = db
|
|
||||||
c.clusterConfig = params.ClusterConfig{Fleet: fleet}
|
|
||||||
c.communityTokensService = collectiblesServiceMock
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -834,7 +834,9 @@ func (m *Messenger) Start() (*MessengerResponse, error) {
|
||||||
m.startSyncSettingsLoop()
|
m.startSyncSettingsLoop()
|
||||||
m.startSettingsChangesLoop()
|
m.startSettingsChangesLoop()
|
||||||
m.startCommunityRekeyLoop()
|
m.startCommunityRekeyLoop()
|
||||||
m.startCuratedCommunitiesUpdateLoop()
|
if m.config.codeControlFlags.CuratedCommunitiesUpdateLoopEnabled {
|
||||||
|
m.startCuratedCommunitiesUpdateLoop()
|
||||||
|
}
|
||||||
m.startMessageSegmentsCleanupLoop()
|
m.startMessageSegmentsCleanupLoop()
|
||||||
|
|
||||||
if err := m.cleanTopics(); err != nil {
|
if err := m.cleanTopics(); err != nil {
|
||||||
|
@ -960,7 +962,7 @@ func (m *Messenger) handleConnectionChange(online bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start fetching messages from store nodes
|
// Start fetching messages from store nodes
|
||||||
if online && m.config.featureFlags.AutoRequestHistoricMessages {
|
if online && m.config.codeControlFlags.AutoRequestHistoricMessages {
|
||||||
m.asyncRequestAllHistoricMessages()
|
m.asyncRequestAllHistoricMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,7 @@ func newTestMessenger(waku types.Waku, config testMessengerConfig) (*Messenger,
|
||||||
WithDatasync(),
|
WithDatasync(),
|
||||||
WithToplevelDatabaseMigrations(),
|
WithToplevelDatabaseMigrations(),
|
||||||
WithBrowserDatabase(nil),
|
WithBrowserDatabase(nil),
|
||||||
|
WithCuratedCommunitiesUpdateLoop(false),
|
||||||
}
|
}
|
||||||
options = append(options, config.extraOptions...)
|
options = append(options, config.extraOptions...)
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,8 @@ type config struct {
|
||||||
// Config for the envelopes monitor
|
// Config for the envelopes monitor
|
||||||
envelopesMonitorConfig *transport.EnvelopesMonitorConfig
|
envelopesMonitorConfig *transport.EnvelopesMonitorConfig
|
||||||
|
|
||||||
featureFlags common.FeatureFlags
|
featureFlags common.FeatureFlags
|
||||||
|
codeControlFlags common.CodeControlFlags
|
||||||
|
|
||||||
appDb *sql.DB
|
appDb *sql.DB
|
||||||
walletDb *sql.DB
|
walletDb *sql.DB
|
||||||
|
@ -125,7 +126,8 @@ func messengerDefaultConfig() config {
|
||||||
messageResendMaxCount: 3,
|
messageResendMaxCount: 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.featureFlags.AutoRequestHistoricMessages = true
|
c.codeControlFlags.AutoRequestHistoricMessages = true
|
||||||
|
c.codeControlFlags.CuratedCommunitiesUpdateLoopEnabled = true
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,10 +411,3 @@ func WithAccountManager(accountManager account.Manager) Option {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithAutoRequestHistoricMessages(enabled bool) Option {
|
|
||||||
return func(c *config) error {
|
|
||||||
c.featureFlags.AutoRequestHistoricMessages = enabled
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package protocol
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"github.com/status-im/status-go/appdatabase"
|
||||||
|
"github.com/status-im/status-go/params"
|
||||||
|
"github.com/status-im/status-go/services/mailservers"
|
||||||
|
"github.com/status-im/status-go/t/helpers"
|
||||||
|
)
|
||||||
|
|
||||||
|
func WithTestStoreNode(s *suite.Suite, id string, address string, fleet string, collectiblesServiceMock *CollectiblesServiceMock) Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
sqldb, err := helpers.SetupTestMemorySQLDB(appdatabase.DbInitializer{})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
db := mailservers.NewDB(sqldb)
|
||||||
|
err = db.Add(mailservers.Mailserver{
|
||||||
|
ID: id,
|
||||||
|
Name: id,
|
||||||
|
Address: address,
|
||||||
|
Fleet: fleet,
|
||||||
|
})
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
c.mailserversDatabase = db
|
||||||
|
c.clusterConfig = params.ClusterConfig{Fleet: fleet}
|
||||||
|
c.communityTokensService = collectiblesServiceMock
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithAutoRequestHistoricMessages(enabled bool) Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.codeControlFlags.AutoRequestHistoricMessages = enabled
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithCuratedCommunitiesUpdateLoop(enabled bool) Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.codeControlFlags.CuratedCommunitiesUpdateLoopEnabled = enabled
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,7 +20,12 @@ const (
|
||||||
|
|
||||||
// Regularly gets list of curated communities and signals them to client
|
// Regularly gets list of curated communities and signals them to client
|
||||||
func (m *Messenger) startCuratedCommunitiesUpdateLoop() {
|
func (m *Messenger) startCuratedCommunitiesUpdateLoop() {
|
||||||
logger := m.logger.Named("startCuratedCommunitiesUpdateLoop")
|
logger := m.logger.Named("curatedCommunitiesUpdateLoop")
|
||||||
|
|
||||||
|
if m.contractMaker == nil {
|
||||||
|
logger.Warn("not starting curated communities loop: contract maker not initialized")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// Initialize interval to 0 for immediate execution
|
// Initialize interval to 0 for immediate execution
|
||||||
|
@ -76,7 +81,6 @@ func (m *Messenger) startCuratedCommunitiesUpdateLoop() {
|
||||||
|
|
||||||
func (m *Messenger) getCuratedCommunitiesFromContract() (*communities.CuratedCommunities, error) {
|
func (m *Messenger) getCuratedCommunitiesFromContract() (*communities.CuratedCommunities, error) {
|
||||||
if m.contractMaker == nil {
|
if m.contractMaker == nil {
|
||||||
m.logger.Warn("contract maker not initialized")
|
|
||||||
return nil, errors.New("contract maker not initialized")
|
return nil, errors.New("contract maker not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -409,7 +409,7 @@ func (m *Messenger) connectToMailserver(ms mailservers.Mailserver) error {
|
||||||
signal.SendMailserverAvailable(m.mailserverCycle.activeMailserver.Address, m.mailserverCycle.activeMailserver.ID)
|
signal.SendMailserverAvailable(m.mailserverCycle.activeMailserver.Address, m.mailserverCycle.activeMailserver.ID)
|
||||||
|
|
||||||
// Query mailserver
|
// Query mailserver
|
||||||
if m.config.featureFlags.AutoRequestHistoricMessages {
|
if m.config.codeControlFlags.AutoRequestHistoricMessages {
|
||||||
go func() {
|
go func() {
|
||||||
_, err := m.performMailserverRequest(&ms, func(_ mailservers.Mailserver) (*MessengerResponse, error) {
|
_, err := m.performMailserverRequest(&ms, func(_ mailservers.Mailserver) (*MessengerResponse, error) {
|
||||||
return m.RequestAllHistoricMessages(false, false)
|
return m.RequestAllHistoricMessages(false, false)
|
||||||
|
@ -564,7 +564,7 @@ func (m *Messenger) handleMailserverCycleEvent(connectedPeers []ConnectedPeer) e
|
||||||
signal.SendMailserverAvailable(m.mailserverCycle.activeMailserver.Address, m.mailserverCycle.activeMailserver.ID)
|
signal.SendMailserverAvailable(m.mailserverCycle.activeMailserver.Address, m.mailserverCycle.activeMailserver.ID)
|
||||||
}
|
}
|
||||||
// Query mailserver
|
// Query mailserver
|
||||||
if m.config.featureFlags.AutoRequestHistoricMessages {
|
if m.config.codeControlFlags.AutoRequestHistoricMessages {
|
||||||
go func() {
|
go func() {
|
||||||
_, err := m.RequestAllHistoricMessages(false, true)
|
_, err := m.RequestAllHistoricMessages(false, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -131,6 +131,7 @@ func (s *MessengerStoreNodeCommunitySuite) newMessenger(name, storenodeAddress s
|
||||||
|
|
||||||
options := []Option{
|
options := []Option{
|
||||||
WithAutoRequestHistoricMessages(false),
|
WithAutoRequestHistoricMessages(false),
|
||||||
|
WithCuratedCommunitiesUpdateLoop(false),
|
||||||
}
|
}
|
||||||
|
|
||||||
if storenodeAddress != "" {
|
if storenodeAddress != "" {
|
||||||
|
|
|
@ -219,6 +219,7 @@ func (s *MessengerStoreNodeRequestSuite) newMessenger(shh types.Waku, logger *za
|
||||||
|
|
||||||
options := []Option{
|
options := []Option{
|
||||||
WithAutoRequestHistoricMessages(false),
|
WithAutoRequestHistoricMessages(false),
|
||||||
|
WithCuratedCommunitiesUpdateLoop(false),
|
||||||
}
|
}
|
||||||
|
|
||||||
if mailserverAddress != "" {
|
if mailserverAddress != "" {
|
||||||
|
@ -1233,7 +1234,7 @@ func (s *MessengerStoreNodeRequestSuite) TestFetchingHistoryWhenOnline() {
|
||||||
{
|
{
|
||||||
// Enable auto request historic messages, so that when bob goes online it will fetch historic messages
|
// Enable auto request historic messages, so that when bob goes online it will fetch historic messages
|
||||||
// We don't enable it earlier to control when we connect to the store node.
|
// We don't enable it earlier to control when we connect to the store node.
|
||||||
s.bob.config.featureFlags.AutoRequestHistoricMessages = true
|
s.bob.config.codeControlFlags.AutoRequestHistoricMessages = true
|
||||||
|
|
||||||
WaitForPeersConnected(&s.Suite, gethbridge.GetGethWakuV2From(s.bobWaku), func() []string {
|
WaitForPeersConnected(&s.Suite, gethbridge.GetGethWakuV2From(s.bobWaku), func() []string {
|
||||||
err := s.bob.DialPeer(storeAddress)
|
err := s.bob.DialPeer(storeAddress)
|
||||||
|
|
Loading…
Reference in New Issue