fix flaky test TestBackupSettings (#4772)
This commit is contained in:
parent
e2cab1a8ae
commit
569a401643
|
@ -8,6 +8,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/status-im/status-go/protocol/identity"
|
"github.com/status-im/status-go/protocol/identity"
|
||||||
|
"github.com/status-im/status-go/protocol/wakusync"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
@ -388,13 +389,13 @@ func (s *MessengerBackupSuite) TestBackupSettings() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Wait for the message to reach its destination
|
// Wait for the message to reach its destination
|
||||||
_, err = WaitOnMessengerResponse(
|
_, err = WaitOnSignaledSendWakuFetchingBackupProgress(bob2, func(r *wakusync.WakuBackedUpDataResponse) bool {
|
||||||
bob2,
|
detailsMap := r.FetchingBackedUpDataDetails()
|
||||||
func(r *MessengerResponse) bool {
|
if settingDetails, ok := detailsMap[SyncWakuSectionKeySettings]; ok {
|
||||||
return r.BackupHandled
|
return settingDetails.DataNumber == settingDetails.TotalNumber
|
||||||
},
|
}
|
||||||
"no messages",
|
return false
|
||||||
)
|
}, "no messages")
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Check bob2
|
// Check bob2
|
||||||
|
|
|
@ -9,6 +9,8 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/status-im/status-go/protocol/wakusync"
|
||||||
|
|
||||||
"github.com/status-im/status-go/protocol/identity"
|
"github.com/status-im/status-go/protocol/identity"
|
||||||
|
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
|
@ -52,8 +54,18 @@ func WaitOnMessengerResponse(m *Messenger, condition func(*MessengerResponse) bo
|
||||||
type MessengerSignalsHandlerMock struct {
|
type MessengerSignalsHandlerMock struct {
|
||||||
MessengerSignalsHandler
|
MessengerSignalsHandler
|
||||||
|
|
||||||
responseChan chan *MessengerResponse
|
responseChan chan *MessengerResponse
|
||||||
communityFoundChan chan *communities.Community
|
communityFoundChan chan *communities.Community
|
||||||
|
wakuBackedUpDataResponseChan chan *wakusync.WakuBackedUpDataResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MessengerSignalsHandlerMock) SendWakuFetchingBackupProgress(response *wakusync.WakuBackedUpDataResponse) {
|
||||||
|
m.wakuBackedUpDataResponseChan <- response
|
||||||
|
}
|
||||||
|
func (m *MessengerSignalsHandlerMock) SendWakuBackedUpProfile(*wakusync.WakuBackedUpDataResponse) {}
|
||||||
|
func (m *MessengerSignalsHandlerMock) SendWakuBackedUpSettings(*wakusync.WakuBackedUpDataResponse) {}
|
||||||
|
func (m *MessengerSignalsHandlerMock) SendWakuBackedUpKeypair(*wakusync.WakuBackedUpDataResponse) {}
|
||||||
|
func (m *MessengerSignalsHandlerMock) SendWakuBackedUpWatchOnlyAccount(*wakusync.WakuBackedUpDataResponse) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MessengerSignalsHandlerMock) MessengerResponse(response *MessengerResponse) {
|
func (m *MessengerSignalsHandlerMock) MessengerResponse(response *MessengerResponse) {
|
||||||
|
@ -73,6 +85,42 @@ func (m *MessengerSignalsHandlerMock) CommunityInfoFound(community *communities.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WaitOnSignaledSendWakuFetchingBackupProgress(m *Messenger, condition func(*wakusync.WakuBackedUpDataResponse) bool, errorMessage string) (*wakusync.WakuBackedUpDataResponse, error) {
|
||||||
|
interval := 500 * time.Millisecond
|
||||||
|
timeoutChan := time.After(10 * time.Second)
|
||||||
|
|
||||||
|
if m.config.messengerSignalsHandler != nil {
|
||||||
|
return nil, errors.New("messengerSignalsHandler already provided/mocked")
|
||||||
|
}
|
||||||
|
|
||||||
|
responseChan := make(chan *wakusync.WakuBackedUpDataResponse, 1000)
|
||||||
|
m.config.messengerSignalsHandler = &MessengerSignalsHandlerMock{
|
||||||
|
wakuBackedUpDataResponseChan: responseChan,
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
m.config.messengerSignalsHandler = nil
|
||||||
|
}()
|
||||||
|
|
||||||
|
for {
|
||||||
|
_, err := m.RetrieveAll()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case r := <-responseChan:
|
||||||
|
if condition(r) {
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
|
case <-timeoutChan:
|
||||||
|
return nil, errors.New("timed out: " + errorMessage)
|
||||||
|
default: // No immediate response, rest & loop back to retrieve again
|
||||||
|
time.Sleep(interval)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func WaitOnSignaledMessengerResponse(m *Messenger, condition func(*MessengerResponse) bool, errorMessage string) (*MessengerResponse, error) {
|
func WaitOnSignaledMessengerResponse(m *Messenger, condition func(*MessengerResponse) bool, errorMessage string) (*MessengerResponse, error) {
|
||||||
interval := 500 * time.Millisecond
|
interval := 500 * time.Millisecond
|
||||||
timeoutChan := time.After(10 * time.Second)
|
timeoutChan := time.After(10 * time.Second)
|
||||||
|
|
Loading…
Reference in New Issue