fix: flaky test TestController_watchAccountChanges by making sure
to check the database transfer after removal event is processed.
This commit is contained in:
parent
bdb2b261a6
commit
440779fc8c
|
@ -150,8 +150,8 @@ func (c *Controller) startAccountWatcher(chainIDs []uint64) {
|
|||
c.accWatcher = accountsevent.NewWatcher(c.accountsDB, c.accountFeed, func(changedAddresses []common.Address, eventType accountsevent.EventType, currentAddresses []common.Address) {
|
||||
c.onAccountsChanged(changedAddresses, eventType, currentAddresses, chainIDs)
|
||||
})
|
||||
c.accWatcher.Start()
|
||||
}
|
||||
c.accWatcher.Start()
|
||||
}
|
||||
|
||||
func (c *Controller) onAccountsChanged(changedAddresses []common.Address, eventType accountsevent.EventType, currentAddresses []common.Address, chainIDs []uint64) {
|
||||
|
|
|
@ -80,26 +80,12 @@ func TestController_watchAccountsChanges(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.NotNil(t, ranges)
|
||||
|
||||
ch := make(chan accountsevent.Event)
|
||||
// Subscribe for account changes
|
||||
accountFeed.Subscribe(ch)
|
||||
c.accWatcher = accountsevent.NewWatcher(c.accountsDB, c.accountFeed, func(changedAddresses []common.Address, eventType accountsevent.EventType, currentAddresses []common.Address) {
|
||||
c.onAccountsChanged(changedAddresses, eventType, currentAddresses, []uint64{chainID})
|
||||
|
||||
// Watching accounts must start before sending event.
|
||||
// To avoid running goroutine immediately, use any delay.
|
||||
// Quit channel event handler before destroying the channel
|
||||
go func() {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
|
||||
accountFeed.Send(accountsevent.Event{
|
||||
Type: accountsevent.EventTypeRemoved,
|
||||
Accounts: []common.Address{address},
|
||||
})
|
||||
}()
|
||||
|
||||
c.startAccountWatcher([]uint64{chainID})
|
||||
|
||||
// Wait for event
|
||||
<-ch
|
||||
|
||||
// Wait for DB to be cleaned up
|
||||
c.accWatcher.Stop()
|
||||
|
||||
|
@ -121,6 +107,21 @@ func TestController_watchAccountsChanges(t *testing.T) {
|
|||
require.Nil(t, ranges.tokens.FirstKnown)
|
||||
require.Nil(t, ranges.tokens.LastKnown)
|
||||
require.Nil(t, ranges.tokens.Start)
|
||||
}()
|
||||
})
|
||||
c.startAccountWatcher([]uint64{chainID})
|
||||
|
||||
// Watching accounts must start before sending event.
|
||||
// To avoid running goroutine immediately and let the controller subscribe first,
|
||||
// use any delay.
|
||||
go func() {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
|
||||
accountFeed.Send(accountsevent.Event{
|
||||
Type: accountsevent.EventTypeRemoved,
|
||||
Accounts: []common.Address{address},
|
||||
})
|
||||
}()
|
||||
}
|
||||
|
||||
func TestController_cleanupAccountLeftovers(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue