Sfoglia il codice sorgente

Add relay test for timeout

tags/v2.0.0-rc1
9seconds 5 anni fa
parent
commit
03d98ee256
1 ha cambiato i file con 19 aggiunte e 0 eliminazioni
  1. 19
    0
      mtglib/internal/relay/relay_test.go

+ 19
- 0
mtglib/internal/relay/relay_test.go Vedi File

2
 
2
 
3
 import (
3
 import (
4
 	"context"
4
 	"context"
5
+	"io"
5
 	"testing"
6
 	"testing"
6
 	"time"
7
 	"time"
7
 
8
 
8
 	"github.com/9seconds/mtg/v2/mtglib/internal/relay"
9
 	"github.com/9seconds/mtg/v2/mtglib/internal/relay"
10
+	"github.com/9seconds/mtg/v2/testlib"
11
+	"github.com/stretchr/testify/mock"
9
 	"github.com/stretchr/testify/suite"
12
 	"github.com/stretchr/testify/suite"
10
 )
13
 )
11
 
14
 
52
 	_ = suite.r.Process(eastConn, westConn)
55
 	_ = suite.r.Process(eastConn, westConn)
53
 }
56
 }
54
 
57
 
58
+func (suite *RelayTestSuite) TestTimeout() {
59
+	eastConn := &rwcMock{}
60
+	eastConn.Write([]byte{1, 2, 3, 4, 5}) // nolint: errcheck
61
+
62
+	westConn := &testlib.NetConnMock{}
63
+	westConn.On("Close").Return(nil)
64
+	westConn.On("Read", mock.Anything).Return(0, io.EOF).Run(func(_ mock.Arguments) {
65
+		time.Sleep(2 * time.Second)
66
+	})
67
+	westConn.On("Write", mock.Anything).Return(0, io.EOF).Run(func(_ mock.Arguments) {
68
+		time.Sleep(2 * time.Second)
69
+	})
70
+
71
+	suite.Error(suite.r.Process(eastConn, westConn))
72
+}
73
+
55
 func TestRelay(t *testing.T) {
74
 func TestRelay(t *testing.T) {
56
 	t.Parallel()
75
 	t.Parallel()
57
 	suite.Run(t, &RelayTestSuite{})
76
 	suite.Run(t, &RelayTestSuite{})

Loading…
Annulla
Salva