From 74fa95fc50d0abf91dea352155832dd203542e74 Mon Sep 17 00:00:00 2001
From: Manuel Kieweg <mail@manuelkieweg.de>
Date: Mon, 8 Mar 2021 18:40:45 +0000
Subject: [PATCH] gracefully end Subscribe()-Test

---
 nucleus/gnmi_transport.go   |  6 ++++--
 nucleus/integration_test.go | 12 ++++++------
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/nucleus/gnmi_transport.go b/nucleus/gnmi_transport.go
index 8a2c22f5d..784a40251 100644
--- a/nucleus/gnmi_transport.go
+++ b/nucleus/gnmi_transport.go
@@ -203,8 +203,10 @@ func (g *Gnmi) subscribe(ctx context.Context) error {
 	go func() {
 		for {
 			resp := <-g.RespChan
-			if err := gnmi.LogSubscribeResponse(resp); err != nil {
-				log.Fatal(err)
+			if resp != nil {
+				if err := gnmi.LogSubscribeResponse(resp); err != nil {
+					log.Fatal(err)
+				}
 			}
 		}
 	}()
diff --git a/nucleus/integration_test.go b/nucleus/integration_test.go
index c92ef12fd..6d19a8528 100644
--- a/nucleus/integration_test.go
+++ b/nucleus/integration_test.go
@@ -5,6 +5,7 @@ import (
 	"code.fbi.h-da.de/cocsn/gosdn/nucleus/util"
 	"context"
 	gpb "github.com/openconfig/gnmi/proto/gnmi"
+	"reflect"
 	"testing"
 	"time"
 )
@@ -95,15 +96,14 @@ func TestGnmi_SubscribeIntegration(t *testing.T) {
 			Target:            address,
 		}
 		ctx := context.WithValue(context.Background(), "opts", opts)
-		d := time.Now().Add(60 * time.Second)
-		ctx, cancel := context.WithDeadline(ctx, d)
-		defer cancel()
 		go func() {
 			if err := transport.Subscribe(ctx); err != nil {
 				t.Error(err)
 			}
 		}()
-		time.Sleep(time.Second * 50)
+		time.Sleep(time.Second * 30)
+		ctx.Done()
+		time.Sleep(time.Second * 5)
 	})
 }
 
@@ -134,8 +134,8 @@ func TestGnmi_CapabilitiesIntegration(t *testing.T) {
 			if err != nil {
 				t.Error(err)
 			}
-			if resp != v {
-				t.Error("resp is nil")
+			if !reflect.DeepEqual(resp, v) {
+				t.Errorf("Capabilities() = %v, want %v", resp, v)
 			}
 		})
 	}
-- 
GitLab