Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,39 @@ func stopTrafficOnFlows(t *testing.T, flowNames []string, ate *ondatra.ATEDevice
flowStop := gosnappi.NewControlState()
flowStop.Traffic().FlowTransmit().SetFlowNames(flowNames).SetState(gosnappi.StateTrafficFlowTransmitState.STOP)
ate.OTG().SetControlState(t, flowStop)

// Wait for traffic flows to confirm transmission stopped.
for _, trafficID := range flowNames {
_, ok := gnmi.Watch(t, ate.OTG(), gnmi.OTG().Flow(trafficID).Transmit().State(), 15*time.Second, func(val *ygnmi.Value[bool]) bool {
txState, present := val.Val()
return present && !txState
}).Await(t)
if !ok {
t.Logf("Flow %s did not transition to stopped state within timeout", trafficID)
}
}

// Wait for in-flight packets to finish draining into receiver.
for _, trafficID := range flowNames {
var lastRx uint64
var unchangedCount int
_, _ = gnmi.Watch(t, ate.OTG(), gnmi.OTG().Flow(trafficID).Counters().InPkts().State(), 15*time.Second, func(val *ygnmi.Value[uint64]) bool {
rx, present := val.Val()
if !present {
return false
}
if rx > 0 && rx == lastRx {
unchangedCount++
if unchangedCount >= 2 {
return true
}
} else {
lastRx = rx
unchangedCount = 0
}
return false
}).Await(t)
Comment on lines +132 to +149

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If a flow does not receive any packets (e.g., due to a traffic generation issue, test failure, or in a negative test scenario), rx will be 0. Because of the rx > 0 guard, the else block will always execute, resetting unchangedCount to 0. This causes the gnmi.Watch to always time out after 15 seconds per flow, unnecessarily delaying the test execution when failures occur.

We can track whether we have received a previous sample using a boolean flag (e.g., hasLastRx) instead of checking rx > 0. This allows the watch to successfully terminate when the counter is stable at 0.

		var lastRx uint64
		var hasLastRx bool
		var unchangedCount int
		_, _ = gnmi.Watch(t, ate.OTG(), gnmi.OTG().Flow(trafficID).Counters().InPkts().State(), 15*time.Second, func(val *ygnmi.Value[uint64]) bool {
			rx, present := val.Val()
			if !present {
				return false
			}
			if hasLastRx && rx == lastRx {
				unchangedCount++
				if unchangedCount >= 2 {
					return true
				}
			} else {
				lastRx = rx
				hasLastRx = true
				unchangedCount = 0
			}
			return false
		}).Await(t)
References
  1. In gNMI telemetry tests, distinguish between cumulative counters and rate metrics: while zero is valid for counters, rates should often be checked for non-zero values (e.g., using IsZero()) to verify active reporting.

}
}

func TestBurstyTraffic(t *testing.T) {
Expand Down Expand Up @@ -442,7 +475,6 @@ func TestBurstyTraffic(t *testing.T) {
t.Logf("Running traffic 1 on DUT interfaces: %s => %s ", dp1.Name(), dp3.Name())
t.Logf("Running traffic 2 on DUT interfaces: %s => %s ", dp2.Name(), dp3.Name())
t.Logf("Sending traffic flows: \n%v\n\n", trafficFlows)
time.Sleep(30 * time.Second)
startTrafficOnFlows(t, flowNames, ate)
time.Sleep(30 * time.Second)
stopTrafficOnFlows(t, flowNames, ate)
Expand Down
Loading