X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=core%2Fconnection_test.go;h=81b145c415bc3aef3aee8d5529895ff8288cc738;hb=a4112fac7b86fe09650d2bb57969fe46404edd7d;hp=2ecdd3420ca93f0886fb003a8de61941d994ab77;hpb=56e997fc27c775790fcce5eda92bb2baee82d881;p=govpp.git diff --git a/core/connection_test.go b/core/connection_test.go index 2ecdd34..81b145c 100644 --- a/core/connection_test.go +++ b/core/connection_test.go @@ -16,15 +16,18 @@ package core_test import ( "testing" + "time" + + . "github.com/onsi/gomega" "git.fd.io/govpp.git/adapter/mock" "git.fd.io/govpp.git/api" + "git.fd.io/govpp.git/binapi/ethernet_types" + interfaces "git.fd.io/govpp.git/binapi/interface" + "git.fd.io/govpp.git/binapi/interface_types" + "git.fd.io/govpp.git/binapi/vpe" "git.fd.io/govpp.git/codec" "git.fd.io/govpp.git/core" - "git.fd.io/govpp.git/examples/bin_api/interfaces" - "git.fd.io/govpp.git/examples/bin_api/stats" - "git.fd.io/govpp.git/examples/bin_api/vpe" - . "github.com/onsi/gomega" ) type testCtx struct { @@ -74,22 +77,27 @@ func TestNilConnection(t *testing.T) { Expect(err.Error()).To(ContainSubstring("nil")) } -func TestDoubleConnection(t *testing.T) { +func TestAsyncConnection(t *testing.T) { ctx := setupTest(t, false) defer ctx.teardownTest() - conn, err := core.Connect(ctx.mockVpp) - Expect(err).Should(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("only one connection per process")) - Expect(conn).Should(BeNil()) + ctx.conn.Disconnect() + conn, statusChan, err := core.AsyncConnect(ctx.mockVpp, core.DefaultMaxReconnectAttempts, core.DefaultReconnectInterval) + ctx.conn = conn + + Expect(err).ShouldNot(HaveOccurred()) + Expect(conn).ShouldNot(BeNil()) + + ev := <-statusChan + Expect(ev.State).Should(BeEquivalentTo(core.Connected)) } -func TestAsyncConnection(t *testing.T) { +func TestAsyncConnectionProcessesVppTimeout(t *testing.T) { ctx := setupTest(t, false) defer ctx.teardownTest() ctx.conn.Disconnect() - conn, statusChan, err := core.AsyncConnect(ctx.mockVpp) + conn, statusChan, err := core.AsyncConnect(ctx.mockVpp, core.DefaultMaxReconnectAttempts, core.DefaultReconnectInterval) ctx.conn = conn Expect(err).ShouldNot(HaveOccurred()) @@ -97,22 +105,29 @@ func TestAsyncConnection(t *testing.T) { ev := <-statusChan Expect(ev.State).Should(BeEquivalentTo(core.Connected)) + + // make control ping reply fail so that connection.healthCheckLoop() + // initiates reconnection. + ctx.mockVpp.MockReply(&vpe.ControlPingReply{ + Retval: -1, + }) + time.Sleep(time.Duration(1+core.HealthCheckThreshold) * (core.HealthCheckInterval + 2*core.HealthCheckReplyTimeout)) } func TestCodec(t *testing.T) { RegisterTestingT(t) - msgCodec := &codec.MsgCodec{} + var msgCodec = codec.DefaultCodec // request - data, err := msgCodec.EncodeMsg(&interfaces.CreateLoopback{MacAddress: []byte{1, 2, 3, 4, 5, 6}}, 11) + data, err := msgCodec.EncodeMsg(&interfaces.CreateLoopback{MacAddress: ethernet_types.MacAddress{1, 2, 3, 4, 5, 6}}, 11) Expect(err).ShouldNot(HaveOccurred()) Expect(data).ShouldNot(BeEmpty()) msg1 := &interfaces.CreateLoopback{} err = msgCodec.DecodeMsg(data, msg1) Expect(err).ShouldNot(HaveOccurred()) - Expect(msg1.MacAddress).To(BeEquivalentTo([]byte{1, 2, 3, 4, 5, 6})) + Expect(msg1.MacAddress).To(BeEquivalentTo(ethernet_types.MacAddress{1, 2, 3, 4, 5, 6})) // reply data, err = msgCodec.EncodeMsg(&vpe.ControlPingReply{Retval: 55}, 22) @@ -123,22 +138,12 @@ func TestCodec(t *testing.T) { err = msgCodec.DecodeMsg(data, msg2) Expect(err).ShouldNot(HaveOccurred()) Expect(msg2.Retval).To(BeEquivalentTo(55)) - - // other - data, err = msgCodec.EncodeMsg(&stats.VnetIP4FibCounters{VrfID: 77}, 33) - Expect(err).ShouldNot(HaveOccurred()) - Expect(data).ShouldNot(BeEmpty()) - - msg3 := &stats.VnetIP4FibCounters{} - err = msgCodec.DecodeMsg(data, msg3) - Expect(err).ShouldNot(HaveOccurred()) - Expect(msg3.VrfID).To(BeEquivalentTo(77)) } func TestCodecNegative(t *testing.T) { RegisterTestingT(t) - msgCodec := &codec.MsgCodec{} + var msgCodec = codec.DefaultCodec // nil message for encoding data, err := msgCodec.EncodeMsg(nil, 15) @@ -154,7 +159,7 @@ func TestCodecNegative(t *testing.T) { // nil data for decoding err = msgCodec.DecodeMsg(nil, &vpe.ControlPingReply{}) Expect(err).Should(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("EOF")) + Expect(err.Error()).To(ContainSubstring("panic")) } func TestSimpleRequestsWithSequenceNumbers(t *testing.T) { @@ -181,7 +186,7 @@ func TestMultiRequestsWithSequenceNumbers(t *testing.T) { var msgs []api.Message for i := 0; i < 10; i++ { - msgs = append(msgs, &interfaces.SwInterfaceDetails{SwIfIndex: uint32(i)}) + msgs = append(msgs, &interfaces.SwInterfaceDetails{SwIfIndex: interface_types.InterfaceIndex(i)}) } ctx.mockVpp.MockReply(msgs...) ctx.mockVpp.MockReply(&vpe.ControlPingReply{}) @@ -300,7 +305,7 @@ func TestMultiRequestsWithErrors(t *testing.T) { } for i := 0; i < 10; i++ { msgs = append(msgs, mock.MsgWithContext{ - Msg: &interfaces.SwInterfaceDetails{SwIfIndex: uint32(i)}, + Msg: &interfaces.SwInterfaceDetails{SwIfIndex: interface_types.InterfaceIndex(i)}, SeqNum: 1, Multipart: true, })