Skip to content

Commit

Permalink
exporter - avoid sending to connections that don't keep up (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
amirylm authored Dec 26, 2021
1 parent c4e25f5 commit e8af295
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions exporter/api/broadcaster_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"context"
"fmt"
"github.com/prysmaticlabs/prysm/async/event"
"github.com/stretchr/testify/require"
Expand All @@ -10,6 +11,15 @@ import (
"time"
)

func TestConn_Send_FullQueue(t *testing.T) {
logger := zaptest.NewLogger(t)
c := newConn(context.Background(), logger, nil, "test", 0)

for i := 0; i < chanSize+2; i++ {
c.Send([]byte(fmt.Sprintf("test-%d", i)))
}
}

func TestBroadcaster(t *testing.T) {
logger := zaptest.NewLogger(t)
b := newBroadcaster(logger)
Expand Down
4 changes: 4 additions & 0 deletions exporter/api/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func (c *conn) ReadNext() []byte {

// Send sends the given message
func (c *conn) Send(msg []byte) {
if len(c.send) >= chanSize {
// don't send on full channel
return
}
c.send <- msg
}

Expand Down

0 comments on commit e8af295

Please sign in to comment.