Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accounts/keystore: faster tests #25827

Merged
merged 6 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
accounts/keystore: add acessors to account cache, to improve tests
  • Loading branch information
holiman committed Oct 6, 2022
commit cf902af07580c5dace0fb8a63a49ce5320dffdf9
8 changes: 8 additions & 0 deletions accounts/keystore/account_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ func (ac *accountCache) deleteByFile(path string) {
}
}

// watcherStarted returns true if the watcher loop started running (even if it
// has since also ended).
func (ac *accountCache) watcherStarted() bool {
ac.mu.Lock()
defer ac.mu.Unlock()
return ac.watcher.running || ac.watcher.runEnded
}

func removeAccount(slice []accounts.Account, elem accounts.Account) []accounts.Account {
for i := range slice {
if slice[i] == elem {
Expand Down
5 changes: 1 addition & 4 deletions accounts/keystore/account_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ func waitWatcherStart(ks *KeyStore) bool {
}
// The watcher should start, and then exit.
for t0 := time.Now(); time.Since(t0) < 1*time.Second; time.Sleep(100 * time.Millisecond) {
ks.cache.mu.Lock()
watchOk := ks.cache.watcher.runEnded || ks.cache.watcher.running
ks.cache.mu.Unlock()
if watchOk {
if ks.cache.watcherStarted() {
return true
}
}
Expand Down
16 changes: 4 additions & 12 deletions accounts/keystore/keystore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,7 @@ func waitForKsUpdating(t *testing.T, ks *KeyStore, wantStatus bool, maxTime time
t.Helper()
// Wait max 250 ms, then return false
for t0 := time.Now(); time.Since(t0) < maxTime; {
ks.mu.RLock()
updating := ks.updating
ks.mu.RUnlock()
if updating == wantStatus {
if ks.isUpdating() == wantStatus {
return true
}
time.Sleep(25 * time.Millisecond)
Expand All @@ -242,11 +239,8 @@ func TestWalletNotifierLifecycle(t *testing.T) {

// Ensure that the notification updater is not running yet
time.Sleep(250 * time.Millisecond)
ks.mu.RLock()
updating := ks.updating
ks.mu.RUnlock()

if updating {
if ks.isUpdating() {
t.Errorf("wallet notifier running without subscribers")
}
// Subscribe to the wallet feed and ensure the updater boots up
Expand All @@ -267,10 +261,8 @@ func TestWalletNotifierLifecycle(t *testing.T) {
}
// Check that it is still running
time.Sleep(250 * time.Millisecond)
ks.mu.RLock()
updating = ks.updating
ks.mu.RUnlock()
if !updating {

if !ks.isUpdating() {
t.Fatal("event notifier stopped prematurely")
}
// Unsubscribe the last one and ensure the updater terminates eventually.
Expand Down