From 17c30ac5329286f1b7c0c1dbb35b4f6cf313ae8b Mon Sep 17 00:00:00 2001 From: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:30:05 +0530 Subject: [PATCH] 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> --- protocol/messenger_backup_test.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/protocol/messenger_backup_test.go b/protocol/messenger_backup_test.go index bba579d9a..5139a2c52 100644 --- a/protocol/messenger_backup_test.go +++ b/protocol/messenger_backup_test.go @@ -8,6 +8,8 @@ import ( "testing" "time" + "go.uber.org/zap" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/event" v1protocol "github.com/status-im/status-go/protocol/v1" @@ -737,32 +739,35 @@ func (s *MessengerBackupSuite) TestBackupKeypairs() { s.Require().NoError(err) 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 - expectedAddresses := [][]common.Address{} - profileKpWalletAddresses := []common.Address{} - seedKpAddresses := []common.Address{} + expectedAddresses := make(map[common.Address]struct{}, 0) for _, acc := range dbProfileKp2.Accounts { if acc.Chat { continue } - profileKpWalletAddresses = append(profileKpWalletAddresses, common.Address(acc.Address)) + expectedAddresses[common.Address(acc.Address)] = struct{}{} } - expectedAddresses = append(expectedAddresses, profileKpWalletAddresses) 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 { case <-time.After(1 * time.Second): s.Fail("Timed out waiting for accountsevent") case event := <-ch: switch event.Type { case accountsevent.EventTypeAdded: - s.Require().Len(event.Accounts, len(expectedAddresses[i])) - s.Require().True(reflect.DeepEqual(expectedAddresses[i], event.Accounts)) + for _, address := range 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") + } + } } } }