fix_: Flaky TestBackupKeypairs test (#5811)
This commit fixes the flaky TestBackupKeypairs test. The flakiness is due to the order in which the backup is processed. The test expects the profile keypair addresses first but sometimes, the non-profile keypair is processed before the profile keypair. This commit updates the test to ensure the received addresses exist in the expected. Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
parent
bbdf5d5ae0
commit
17c30ac532
|
@ -8,6 +8,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
v1protocol "github.com/status-im/status-go/protocol/v1"
|
v1protocol "github.com/status-im/status-go/protocol/v1"
|
||||||
|
@ -737,32 +739,35 @@ func (s *MessengerBackupSuite) TestBackupKeypairs() {
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().True(accounts.SameKeypairsWithDifferentSyncedFrom(seedKp, dbSeedKp2, false, accounts.SyncedFromBackup, accounts.AccountNonOperable))
|
s.Require().True(accounts.SameKeypairsWithDifferentSyncedFrom(seedKp, dbSeedKp2, false, accounts.SyncedFromBackup, accounts.AccountNonOperable))
|
||||||
|
|
||||||
|
keypairs, err := bob2.settings.GetAllKeypairs()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// Check whether accounts added event is sent
|
// Check whether accounts added event is sent
|
||||||
expectedAddresses := [][]common.Address{}
|
expectedAddresses := make(map[common.Address]struct{}, 0)
|
||||||
profileKpWalletAddresses := []common.Address{}
|
|
||||||
seedKpAddresses := []common.Address{}
|
|
||||||
for _, acc := range dbProfileKp2.Accounts {
|
for _, acc := range dbProfileKp2.Accounts {
|
||||||
if acc.Chat {
|
if acc.Chat {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
profileKpWalletAddresses = append(profileKpWalletAddresses, common.Address(acc.Address))
|
expectedAddresses[common.Address(acc.Address)] = struct{}{}
|
||||||
}
|
}
|
||||||
expectedAddresses = append(expectedAddresses, profileKpWalletAddresses)
|
|
||||||
|
|
||||||
for _, acc := range dbSeedKp2.Accounts {
|
for _, acc := range dbSeedKp2.Accounts {
|
||||||
seedKpAddresses = append(seedKpAddresses, common.Address(acc.Address))
|
expectedAddresses[common.Address(acc.Address)] = struct{}{}
|
||||||
}
|
}
|
||||||
expectedAddresses = append(expectedAddresses, seedKpAddresses)
|
|
||||||
|
|
||||||
for i := 0; i < len(expectedAddresses); i++ {
|
for i := 0; i < len(keypairs); i++ {
|
||||||
select {
|
select {
|
||||||
case <-time.After(1 * time.Second):
|
case <-time.After(1 * time.Second):
|
||||||
s.Fail("Timed out waiting for accountsevent")
|
s.Fail("Timed out waiting for accountsevent")
|
||||||
case event := <-ch:
|
case event := <-ch:
|
||||||
switch event.Type {
|
switch event.Type {
|
||||||
case accountsevent.EventTypeAdded:
|
case accountsevent.EventTypeAdded:
|
||||||
s.Require().Len(event.Accounts, len(expectedAddresses[i]))
|
for _, address := range event.Accounts {
|
||||||
s.Require().True(reflect.DeepEqual(expectedAddresses[i], event.Accounts))
|
if _, exists := expectedAddresses[address]; !exists {
|
||||||
|
s.logger.Debug("missing address in the accounts event", zap.Any("address", address))
|
||||||
|
s.Fail("address not received in the event")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue