forked from FDio/govpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream_test.go
63 lines (49 loc) · 1.32 KB
/
stream_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package core
import (
"context"
"testing"
"time"
. "github.com/onsi/gomega"
"go.fd.io/govpp/adapter/mock"
)
type streamCtx struct {
mockVpp *mock.VppAdapter
conn *Connection
stream *Stream
}
func setupStreamTest(t *testing.T) *streamCtx {
RegisterTestingT(t)
ctx := &streamCtx{
mockVpp: mock.NewVppAdapter(),
}
var err error
ctx.conn, err = Connect(ctx.mockVpp)
Expect(err).ShouldNot(HaveOccurred())
stream, err := ctx.conn.NewStream(context.TODO())
Expect(err).ShouldNot(HaveOccurred())
ctx.stream = stream.(*Stream)
return ctx
}
func (ctx *streamCtx) teardownTest() {
err := ctx.stream.Close()
Expect(err).ShouldNot(HaveOccurred())
ctx.conn.Disconnect()
}
func TestStreamReply(t *testing.T) {
ctx := setupStreamTest(t)
defer ctx.teardownTest()
ctx.stream.replyTimeout = time.Millisecond
// mock reply
ctx.mockVpp.MockReply(&ControlPingReply{})
// first one request should work
err := ctx.stream.SendMsg(&ControlPing{})
Expect(err).ShouldNot(HaveOccurred())
_, err = ctx.stream.RecvMsg()
Expect(err).ShouldNot(HaveOccurred())
// no other reply ready - expect timeout
err = ctx.stream.SendMsg(&ControlPing{})
Expect(err).ShouldNot(HaveOccurred())
_, err = ctx.stream.RecvMsg()
Expect(err).Should(HaveOccurred())
Expect(err.Error()).To(HavePrefix("no reply received within the timeout period"))
}