Skip to content

Commit

Permalink
add test case for writer timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
kasey committed Oct 21, 2024
1 parent 443ebdd commit d69752c
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions beacon-chain/rpc/eth/events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,43 @@ func TestStreamEvents_OperationsEvents(t *testing.T) {
})
}

func TestStuckReader(t *testing.T) {
func TestStuckReaderScenarios(t *testing.T) {
cases := []struct {
name string
queueDepth func([]*feed.Event) int
}{
{
name: "slow reader - queue overflows",
queueDepth: func(events []*feed.Event) int {
return len(events) - 1
},
},
{
name: "slow reader - all queued, but writer is stuck, write timeout",
queueDepth: func(events []*feed.Event) int {
return len(events) + 1
},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
wedgedWriterTestCase(t, c.queueDepth)
})
}
}

func wedgedWriterTestCase(t *testing.T, queueDepth func([]*feed.Event) int) {
topics, events := operationEventsFixtures(t)
require.Equal(t, 8, len(events))

// set eventFeedDepth to a number lower than the events we intend to send to force the server to drop the reader.
stn := mockChain.NewEventFeedWrapper()
opn := mockChain.NewEventFeedWrapper()
s := &Server{
EventWriteTimeout: 10 * time.Millisecond,
StateNotifier: &mockChain.SimpleNotifier{Feed: stn},
OperationNotifier: &mockChain.SimpleNotifier{Feed: opn},
EventFeedDepth: len(events) - 1,
EventFeedDepth: queueDepth(events),
}

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
Expand Down

0 comments on commit d69752c

Please sign in to comment.