Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions accounts/keystore/account_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,27 @@ func waitWatcherStart(ks *KeyStore) bool {

func waitForAccounts(wantAccounts []accounts.Account, ks *KeyStore) error {
var list []accounts.Account
haveAccounts := false
haveChange := false
for t0 := time.Now(); time.Since(t0) < 5*time.Second; time.Sleep(100 * time.Millisecond) {
list = ks.Accounts()
if reflect.DeepEqual(list, wantAccounts) {
// ks should have also received change notifications
if !haveAccounts {
list = ks.Accounts()
haveAccounts = reflect.DeepEqual(list, wantAccounts)
}
if !haveChange {
select {
case <-ks.changes:
haveChange = true
default:
return errors.New("wasn't notified of new accounts")
}
}
if haveAccounts && haveChange {
return nil
Comment on lines +74 to 86
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haveAccounts is latched true after the first time ks.Accounts() matches wantAccounts, and the helper stops re-reading the account list. Since the cache update path can expose intermediate states (e.g., scanAccounts processes updates as deleteByFile then add with separate locks), a transient match can be observed and then later diverge; this helper would still return success once a change is seen, or return the "wasn't notified" error even if accounts no longer match. Recompute list/equality each loop (or at least re-check immediately before returning and before deciding the final error) so success requires the current account list equals wantAccounts while still allowing the change and match to happen in either order.

Copilot uses AI. Check for mistakes.
}
}
if haveAccounts {
return errors.New("wasn't notified of new accounts")
}
return fmt.Errorf("\ngot %v\nwant %v", list, wantAccounts)
}

Expand Down
Loading