2022-08-15 05:33:45 -07:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
gossipv1 "github.com/certusone/wormhole/node/pkg/proto/gossip/v1"
|
2022-08-18 01:52:36 -07:00
|
|
|
"github.com/wormhole-foundation/wormhole/sdk/vaa"
|
2022-08-15 05:33:45 -07:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestObsvReqSendLimitEnforced(t *testing.T) {
|
|
|
|
obsvReqSendC := make(chan *gossipv1.ObservationRequest, ObsvReqChannelSize)
|
|
|
|
|
|
|
|
// If the channel overflows, the write hangs, so use a go routine with a timeout.
|
2022-09-20 03:27:04 -07:00
|
|
|
done := make(chan struct{})
|
2022-08-15 05:33:45 -07:00
|
|
|
go func() {
|
|
|
|
// Filling the queue up should work.
|
|
|
|
for count := 1; count <= ObsvReqChannelSize; count++ {
|
|
|
|
req := &gossipv1.ObservationRequest{
|
|
|
|
ChainId: uint32(vaa.ChainIDSolana),
|
|
|
|
}
|
|
|
|
err := PostObservationRequest(obsvReqSendC, req)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// But one more write should fail.
|
|
|
|
req := &gossipv1.ObservationRequest{
|
|
|
|
ChainId: uint32(vaa.ChainIDSolana),
|
|
|
|
}
|
|
|
|
err := PostObservationRequest(obsvReqSendC, req)
|
2022-08-16 23:06:28 -07:00
|
|
|
assert.ErrorIs(t, err, ErrChanFull)
|
2022-08-15 05:33:45 -07:00
|
|
|
|
2022-09-20 03:27:04 -07:00
|
|
|
done <- struct{}{}
|
2022-08-15 05:33:45 -07:00
|
|
|
}()
|
|
|
|
|
2022-09-20 03:27:04 -07:00
|
|
|
timeout := time.NewTimer(time.Second)
|
|
|
|
select {
|
|
|
|
case <-timeout.C:
|
|
|
|
assert.Fail(t, "timed out")
|
|
|
|
case <-done:
|
|
|
|
}
|
2022-08-15 05:33:45 -07:00
|
|
|
}
|