mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 16:01:55 +03:00
Add relay test for timeout
This commit is contained in:
@@ -2,10 +2,13 @@ package relay_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/9seconds/mtg/v2/mtglib/internal/relay"
|
"github.com/9seconds/mtg/v2/mtglib/internal/relay"
|
||||||
|
"github.com/9seconds/mtg/v2/testlib"
|
||||||
|
"github.com/stretchr/testify/mock"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -52,6 +55,22 @@ func (suite *RelayTestSuite) TestCopyFine() {
|
|||||||
_ = suite.r.Process(eastConn, westConn)
|
_ = 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) {
|
func TestRelay(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
suite.Run(t, &RelayTestSuite{})
|
suite.Run(t, &RelayTestSuite{})
|
||||||
|
|||||||
Reference in New Issue
Block a user