Skip to content
Snippets Groups Projects
Commit 74fa95fc authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

gracefully end Subscribe()-Test

parent f6a5e620
No related branches found
No related tags found
2 merge requests!112Integration test,!90Develop
...@@ -203,8 +203,10 @@ func (g *Gnmi) subscribe(ctx context.Context) error { ...@@ -203,8 +203,10 @@ func (g *Gnmi) subscribe(ctx context.Context) error {
go func() { go func() {
for { for {
resp := <-g.RespChan resp := <-g.RespChan
if err := gnmi.LogSubscribeResponse(resp); err != nil { if resp != nil {
log.Fatal(err) if err := gnmi.LogSubscribeResponse(resp); err != nil {
log.Fatal(err)
}
} }
} }
}() }()
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util" "code.fbi.h-da.de/cocsn/gosdn/nucleus/util"
"context" "context"
gpb "github.com/openconfig/gnmi/proto/gnmi" gpb "github.com/openconfig/gnmi/proto/gnmi"
"reflect"
"testing" "testing"
"time" "time"
) )
...@@ -95,15 +96,14 @@ func TestGnmi_SubscribeIntegration(t *testing.T) { ...@@ -95,15 +96,14 @@ func TestGnmi_SubscribeIntegration(t *testing.T) {
Target: address, Target: address,
} }
ctx := context.WithValue(context.Background(), "opts", opts) ctx := context.WithValue(context.Background(), "opts", opts)
d := time.Now().Add(60 * time.Second)
ctx, cancel := context.WithDeadline(ctx, d)
defer cancel()
go func() { go func() {
if err := transport.Subscribe(ctx); err != nil { if err := transport.Subscribe(ctx); err != nil {
t.Error(err) 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) { ...@@ -134,8 +134,8 @@ func TestGnmi_CapabilitiesIntegration(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
if resp != v { if !reflect.DeepEqual(resp, v) {
t.Error("resp is nil") t.Errorf("Capabilities() = %v, want %v", resp, v)
} }
}) })
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment