Refactor code and add txPowerReadingError value#5428
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on refactoring the transceiver power validation tests to improve code quality and consistency. By centralizing validation logic and standardizing constant values, the changes ensure more robust testing of optical channel states and power readings. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors the zr_input_output_power_test.go file to improve modularity and readability by introducing helper functions for interface lifecycle management and consolidating power validation logic. Feedback from the reviewer highlights concerns regarding the increased power thresholds and error tolerances, which may be too permissive for accurate telemetry validation. Suggestions were also provided to mitigate potential test flakiness during state transitions and to enhance the clarity of error messages.
| inactiveOCHRxPower = 0.0 | ||
| inactiveOCHTxPower = 0.0 | ||
| inactiveTransceiverRxPower = 0.0 |
There was a problem hiding this comment.
Setting the inactive power thresholds to 0.0 dBm is extremely permissive. In optical networking, 0.0 dBm (1mW) is a significant amount of power and often falls within the normal operating range of an active transceiver. Typically, values like -30.0 or -40.0 are used to ensure the laser is truly off or no signal is present. Using 0.0 might fail to detect cases where a port is reported as DOWN but is still emitting or receiving significant power.
| inactiveTransceiverRxPower = 0.0 | ||
| rxPowerReadingError = 3 | ||
| txPowerReadingError = 0.5 | ||
| txPowerReadingError = 3 |
There was a problem hiding this comment.
Increasing txPowerReadingError to 3 dB significantly loosens the validation tolerance. A 3 dB difference represents a factor of 2 in power levels. Most ZR specifications and related tests in this repository use a much tighter tolerance, typically between 0.5 and 1.0 dB, to ensure accurate telemetry reporting.
| if operStatus != expectedStatus { | ||
| t.Errorf("Invalid %v operStatus value: want %v, got %v", p.Name(), expectedStatus, operStatus) | ||
| } |
There was a problem hiding this comment.
This check is likely to cause test flakiness. The samplestream starts collecting data before the interface is toggled, and gnmi.Await waits for the status to change. Consequently, the stream will contain samples from the transition period where the operStatus is still the old value. Since validateSampleStream already verifies that power levels are correct for the status reported in each sample, failing the test here for status mismatches is unnecessary and prone to error.
| if operStatus != expectedStatus { | |
| t.Errorf("Invalid %v operStatus value: want %v, got %v", p.Name(), expectedStatus, operStatus) | |
| } | |
| if operStatus != expectedStatus { | |
| continue | |
| } |
| } | ||
|
|
||
| if !isValid { | ||
| t.Errorf("Invalid %v sample when %v is %v --> min : %v, max : %v, avg : %v, instant : %v", pm, portName, operStatus, min, max, avg, instant) |
There was a problem hiding this comment.
The error message would be more useful for debugging if it included the expected validation bounds (minAllowed, maxAllowed, or inactiveValue) that caused the failure.
| t.Errorf("Invalid %v sample when %v is %v --> min : %v, max : %v, avg : %v, instant : %v", pm, portName, operStatus, min, max, avg, instant) | |
| t.Errorf("Invalid %v sample when %v is %v --> min: %v, max: %v, avg: %v, instant: %v (expected range [%v, %v] or inactive <= %v)", pm, portName, operStatus, min, max, avg, instant, minAllowed, maxAllowed, inactiveValue) |
The changes include