mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 15:14:03 +03:00
Add relay test for timeout
This commit is contained in:
@@ -2,10 +2,13 @@ package relay_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/9seconds/mtg/v2/mtglib/internal/relay"
|
||||
"github.com/9seconds/mtg/v2/testlib"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
@@ -52,6 +55,22 @@ func (suite *RelayTestSuite) TestCopyFine() {
|
||||
_ = suite.r.Process(eastConn, westConn)
|
||||
}
|
||||
|
||||
func (suite *RelayTestSuite) TestTimeout() {
|
||||
eastConn := &rwcMock{}
|
||||
eastConn.Write([]byte{1, 2, 3, 4, 5}) // nolint: errcheck
|
||||
|
||||
westConn := &testlib.NetConnMock{}
|
||||
westConn.On("Close").Return(nil)
|
||||
westConn.On("Read", mock.Anything).Return(0, io.EOF).Run(func(_ mock.Arguments) {
|
||||
time.Sleep(2 * time.Second)
|
||||
})
|
||||
westConn.On("Write", mock.Anything).Return(0, io.EOF).Run(func(_ mock.Arguments) {
|
||||
time.Sleep(2 * time.Second)
|
||||
})
|
||||
|
||||
suite.Error(suite.r.Process(eastConn, westConn))
|
||||
}
|
||||
|
||||
func TestRelay(t *testing.T) {
|
||||
t.Parallel()
|
||||
suite.Run(t, &RelayTestSuite{})
|
||||
|
||||
Reference in New Issue
Block a user