Skip to content

Commit

Permalink
refactor concurrency analysis gNMI-1.14 (openconfig#2638)
Browse files Browse the repository at this point in the history
- obtain getRequest timestamps
- compare with setRequest timestamps
- Increase debugability (show timestamps for each thread)

"This code is a Contribution to the OpenConfig Feature Profiles project ("Work") made under the Google Software Grant and Corporate Contributor License Agreement ("CLA") and governed by the Apache License 2.0. No other rights or licenses in or to any of Nokia's intellectual property are granted for any other purpose. This code is provided on an "as is" basis without any warranties of any kind."
  • Loading branch information
MarcCharlebois authored and frasieroh committed Feb 21, 2024
1 parent cb8bf16 commit 16920b0
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ func buildGNMIUpdate(t *testing.T, yPath ygnmi.PathStruct, val any) *gpb.Update
}

// extractMetadataAnnotation extracts the metadata protobuf message from a gNMI GetResponse.
func extractMetadataAnnotation(t *testing.T, gnmiClient gpb.GNMIClient, dut *ondatra.DUTDevice) string {
func extractMetadataAnnotation(t *testing.T, gnmiClient gpb.GNMIClient, dut *ondatra.DUTDevice) (string, int64) {
ns := getNotificationsUsingGNMIGet(t, gnmiClient, dut)
var getRespTimeStamp int64
if got := len(ns); got == 0 {
t.Fatalf("number of notifications got %d, want > 0", got)
}

var annotation any
for _, n := range ns {
getRespTimeStamp = n.GetTimestamp()
for _, u := range n.GetUpdate() {
path, err := util.JoinPaths(new(gpb.Path), u.GetPath())
if err != nil || len(path.GetElem()) > 0 {
Expand Down Expand Up @@ -185,7 +187,7 @@ func extractMetadataAnnotation(t *testing.T, gnmiClient gpb.GNMIClient, dut *ond
if err := proto.Unmarshal(decoded, msg); err != nil {
t.Fatalf("cannot unmarshal received proto any msg, err: %v", err)
}
return msg.GetName()
return msg.GetName(), getRespTimeStamp
}

// buildGNMISetRequest builds gnmi set request with protobuf-metadata
Expand Down Expand Up @@ -239,13 +241,14 @@ func getNotificationsUsingGNMIGet(t *testing.T, gnmiClient gpb.GNMIClient, dut *
}

// checkMetadata checks protobuf-metadata
func checkMetadata(t *testing.T, gnmiClient gpb.GNMIClient, dut *ondatra.DUTDevice, done *atomic.Bool) {
func checkMetadata(t *testing.T, gnmiClient gpb.GNMIClient, dut *ondatra.DUTDevice, done *atomic.Int64) {
t.Helper()

got := extractMetadataAnnotation(t, gnmiClient, dut)
got, getRespTimeStamp := extractMetadataAnnotation(t, gnmiClient, dut)

want := metadata1
if done.Load() {
t.Logf("SetResp: %v, getResp: %v ", done.Load(), getRespTimeStamp)
if done.Load() > 0 && done.Load() < getRespTimeStamp {
want = metadata2
}
if got != want {
Expand All @@ -254,8 +257,7 @@ func checkMetadata(t *testing.T, gnmiClient gpb.GNMIClient, dut *ondatra.DUTDevi
}

func TestLargeSetConsistency(t *testing.T) {
done := &atomic.Bool{}
done.Store(false)
done := &atomic.Int64{}
dut := ondatra.DUT(t, "dut")

// configuring basic interface and network instance as some devices only populate OC after configuration
Expand Down Expand Up @@ -289,12 +291,13 @@ func TestLargeSetConsistency(t *testing.T) {
go func() {
defer wg.Done()
t.Log("gnmiClient Set 2nd large config")
if _, err := gnmiClient.Set(context.Background(), gpbSetRequest); err != nil {
setResp, err := gnmiClient.Set(context.Background(), gpbSetRequest)
if err != nil {
t.Errorf("gnmi.Set unexpected error: %v", err)
return
}
close(ch)
done.Store(true)
done.Store(setResp.GetTimestamp())
}()

// sending 4 Get requests concurrently every 5 seconds.
Expand Down

0 comments on commit 16920b0

Please sign in to comment.