Skip to content

Commit

Permalink
Merge pull request #1771 from CortexFoundation/dev
Browse files Browse the repository at this point in the history
fix flaky test TestPendingTxFilterDeadlock
  • Loading branch information
ucwong authored Oct 21, 2023
2 parents 3f2ce69 + 1d0d084 commit a34ff66
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions ctxc/filters/filter_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,14 @@ func TestPendingTxFilterDeadlock(t *testing.T) {

// Create a bunch of filters that will
// timeout either in 100ms or 200ms
fids := make([]rpc.ID, 20)
for i := 0; i < len(fids); i++ {
subs := make([]*Subscription, 20)
for i := 0; i < len(subs); i++ {
fid := api.NewPendingTransactionFilter()
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
for {
hashes, err := api.GetFilterChanges(fid)
Expand All @@ -660,21 +664,13 @@ func TestPendingTxFilterDeadlock(t *testing.T) {
}
}

// Wait until filters have timed out
time.Sleep(3 * timeout)

// If tx loop doesn't consume `done` after a second
// it's hanging.
select {
case done <- struct{}{}:
// 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)
}
// Wait until filters have timed out and have been uninstalled.
for _, sub := range subs {
select {
case <-sub.Err():
case <-time.After(1 * time.Second):
t.Fatalf("Filter timeout is hanging")
}
case <-time.After(1 * time.Second):
t.Error("Tx sending loop hangs")
}
}

Expand Down

0 comments on commit a34ff66

Please sign in to comment.