avoid timeout

This commit is contained in:
Sina Mahmoodi 2023-10-18 17:35:42 +02:00
parent 92efe61719
commit 1f6b8cd610

View file

@ -915,10 +915,14 @@ func TestPendingTxFilterDeadlock(t *testing.T) {
// Create a bunch of filters that will // Create a bunch of filters that will
// timeout either in 100ms or 200ms // timeout either in 100ms or 200ms
fids := make([]rpc.ID, 20) subs := make([]*Subscription, 20)
for i := 0; i < len(fids); i++ { for i := 0; i < len(subs); i++ {
fid := api.NewPendingTransactionFilter(nil) fid := api.NewPendingTransactionFilter(nil)
fids[i] = fid f, ok := api.filters[fid]
if !ok {
t.Fatalf("Filter %s should exist", fid)
}
subs[i] = f.s
// Wait for at least one tx to arrive in filter // Wait for at least one tx to arrive in filter
for { for {
hashes, err := api.GetFilterChanges(fid) hashes, err := api.GetFilterChanges(fid)
@ -932,21 +936,13 @@ func TestPendingTxFilterDeadlock(t *testing.T) {
} }
} }
// Wait until filters have timed out // Wait until filters have timed out and have been uninstalled.
time.Sleep(6 * timeout) for _, sub := range subs {
// If tx loop doesn't consume `done` after a second
// it's hanging.
select { select {
case done <- struct{}{}: case <-sub.Err():
// Check that all filters have been uninstalled
for _, fid := range fids {
if _, err := api.GetFilterChanges(fid); err == nil {
t.Errorf("Filter %s should have been uninstalled\n", fid)
}
}
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
t.Error("Tx sending loop hangs") t.Fatalf("Filter %s should have been uninstalled\n", sub.ID)
}
} }
} }