test: Fix test dependancy
[govpp.git] / core / connection_test.go
index 453bbce..81b145c 100644 (file)
 package core_test
 
 import (
-       "git.fd.io/govpp.git/examples/binapi/interface_types"
        "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/binapi/interfaces"
-       "git.fd.io/govpp.git/examples/binapi/vpe"
 )
 
 type testCtx struct {
@@ -90,20 +92,42 @@ func TestAsyncConnection(t *testing.T) {
        Expect(ev.State).Should(BeEquivalentTo(core.Connected))
 }
 
+func TestAsyncConnectionProcessesVppTimeout(t *testing.T) {
+       ctx := setupTest(t, false)
+       defer ctx.teardownTest()
+
+       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))
+
+       // 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)
 
        var msgCodec = codec.DefaultCodec
 
        // request
-       data, err := msgCodec.EncodeMsg(&interfaces.CreateLoopback{MacAddress: interfaces.MacAddress{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(interfaces.MacAddress{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)