-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix endless Stream's reply waiting on vpp disconnect (#77)
- Loading branch information
Showing
2 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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")) | ||
} |