Fix race condition in cisco telemetry tests (#5979)
This commit is contained in:
parent
968714054a
commit
5de7bdf906
|
@ -62,6 +62,13 @@ func (m *mockGNMIServer) Subscribe(server gnmi.GNMI_SubscribeServer) error {
|
|||
require.Equal(m.t, metadata.Get("username"), []string{"theuser"})
|
||||
require.Equal(m.t, metadata.Get("password"), []string{"thepassword"})
|
||||
|
||||
// Must read request before sending a response; even though we don't check
|
||||
// the request itself currently.
|
||||
_, err := server.Recv()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
switch m.scenario {
|
||||
case 0:
|
||||
return fmt.Errorf("testerror")
|
||||
|
@ -91,7 +98,8 @@ func (m *mockGNMIServer) Subscribe(server gnmi.GNMI_SubscribeServer) error {
|
|||
}
|
||||
|
||||
func TestGNMIError(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
server := grpc.NewServer()
|
||||
acc := &testutil.Accumulator{}
|
||||
gnmi.RegisterGNMIServer(server, &mockGNMIServer{t: t, scenario: 0, server: server, acc: acc})
|
||||
|
@ -100,8 +108,11 @@ func TestGNMIError(t *testing.T) {
|
|||
Username: "theuser", Password: "thepassword", Encoding: "proto",
|
||||
Redial: internal.Duration{Duration: 1 * time.Second}}
|
||||
|
||||
require.Nil(t, c.Start(acc))
|
||||
go server.Serve(listener)
|
||||
require.NoError(t, c.Start(acc))
|
||||
go func() {
|
||||
err := server.Serve(listener)
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
acc.WaitError(1)
|
||||
c.Stop()
|
||||
server.Stop()
|
||||
|
@ -157,7 +168,8 @@ func mockGNMINotification() *gnmi.Notification {
|
|||
}
|
||||
|
||||
func TestGNMIMultiple(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
server := grpc.NewServer()
|
||||
acc := &testutil.Accumulator{}
|
||||
gnmi.RegisterGNMIServer(server, &mockGNMIServer{t: t, scenario: 1, server: server, acc: acc})
|
||||
|
@ -168,9 +180,11 @@ func TestGNMIMultiple(t *testing.T) {
|
|||
Subscriptions: []Subscription{{Name: "alias", Origin: "type", Path: "/model", SubscriptionMode: "sample"}},
|
||||
}
|
||||
|
||||
require.Nil(t, c.Start(acc))
|
||||
|
||||
go server.Serve(listener)
|
||||
require.NoError(t, c.Start(acc))
|
||||
go func() {
|
||||
err := server.Serve(listener)
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
acc.Wait(4)
|
||||
c.Stop()
|
||||
server.Stop()
|
||||
|
@ -195,7 +209,8 @@ func TestGNMIMultiple(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGNMIMultipleRedial(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
listener, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
require.NoError(t, err)
|
||||
server := grpc.NewServer()
|
||||
acc := &testutil.Accumulator{}
|
||||
gnmi.RegisterGNMIServer(server, &mockGNMIServer{t: t, scenario: 2, server: server, acc: acc})
|
||||
|
@ -206,9 +221,11 @@ func TestGNMIMultipleRedial(t *testing.T) {
|
|||
Subscriptions: []Subscription{{Name: "alias", Origin: "type", Path: "/model", SubscriptionMode: "sample"}},
|
||||
}
|
||||
|
||||
require.Nil(t, c.Start(acc))
|
||||
|
||||
go server.Serve(listener)
|
||||
require.NoError(t, c.Start(acc))
|
||||
go func() {
|
||||
err := server.Serve(listener)
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
acc.Wait(2)
|
||||
server.Stop()
|
||||
|
||||
|
@ -216,7 +233,10 @@ func TestGNMIMultipleRedial(t *testing.T) {
|
|||
server = grpc.NewServer()
|
||||
gnmi.RegisterGNMIServer(server, &mockGNMIServer{t: t, scenario: 3, server: server, acc: acc})
|
||||
|
||||
go server.Serve(listener)
|
||||
go func() {
|
||||
err := server.Serve(listener)
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
acc.Wait(4)
|
||||
c.Stop()
|
||||
server.Stop()
|
||||
|
|
Loading…
Reference in New Issue