Fix flakey TestWalletNotifications test #30146
Closed
+25
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TestWalletNotifications has two intermittent failures called out here.
keystore_test.go:427: wallet list doesn't match required accounts: have 491, want 490
Problem: The receiver routine shouldn't have been closing the channel as pointed out in an example here. The event collector routine was not waiting for the key store to finish updating.
Solution:
This is fixed with test only changes by waiting for the key store to finish updating before closing the updates and collecting the events.
keystore_test.go:455: can't find event with Kind=2 for 56fe5c503fb7f1850298b7d6896cfd8019b525e1
Problem: After a wallet is dropped, there is a chance it would get added again. I haven't been able to pinpoint whether this is due to the temporary file store used in the tests or some other concurrency issue. At any rate, I'm assuming we wouldn't want duplicate wallet add notifications, and it'd be great if someone could confirm this assumption as correct or false.
Solution
While the changes I've made to keystore.go appear to fix the issue, it feels like a bandaid more than an ideal fix, and it's based on an assumption that we shouldn't get duplicate add notifications. I'd love to get someone's advice on the preferred route forward here.
Observations
os.Remove(a.URL.Path)
in(ks *KeyStore) Delete
. This leads me to believe it may be a race issue with rapid file deletions and adds.Testing
Hardware: Apple M1 Max, 64 GB, Sonoma 14.5
Ran
go test -c && stress ./keystore.test -test.run=TestWalletNotifications -test.v
for 5 minutesmain:
5m0s: 2103 runs so far, 25 failures (1.19%)
this branch:
5m0s: 2028 runs so far, 0 failures