Skip to content

Commit 2f4ba56

Browse files
authored
usm: http2: Fixed a flaky test (#21260)
* usm: http2: Fixed a flaky test * Fixed CR comment
1 parent 88aa89e commit 2f4ba56

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

pkg/network/usm/monitor_test.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -825,14 +825,11 @@ func (s *USMHTTP2Suite) TestHTTP2KernelTelemetry() {
825825
},
826826

827827
expectedTelemetry: &usmhttp2.HTTP2Telemetry{
828-
Request_seen: 8,
829-
Response_seen: 8,
830-
End_of_stream: 16,
831-
End_of_stream_rst: 0,
832-
Path_exceeds_frame: 0,
833-
Exceeding_max_interesting_frames: 0,
834-
Exceeding_max_frames_to_filter: 0,
835-
Path_size_bucket: [8]uint64{1, 1, 1, 1, 1, 1, 1, 1},
828+
Request_seen: 8,
829+
Response_seen: 8,
830+
End_of_stream: 16,
831+
End_of_stream_rst: 0,
832+
Path_size_bucket: [8]uint64{1, 1, 1, 1, 1, 1, 1, 1},
836833
},
837834
},
838835
}
@@ -845,11 +842,22 @@ func (s *USMHTTP2Suite) TestHTTP2KernelTelemetry() {
845842

846843
tt.runClients(t, 1)
847844

845+
// We cannot predict if the client will send an RST frame or not, thus we cannot predict the number of
846+
// frames with EOS or RST frames, which leads into a flaking test. Therefore, we are asserting that the
847+
// gotten number of EOS or RST frames is at least the number of expected EOS frames.
848+
expectedEOSOrRST := tt.expectedTelemetry.End_of_stream + tt.expectedTelemetry.End_of_stream_rst
848849
var telemetry *usmhttp2.HTTP2Telemetry
849850
assert.Eventually(t, func() bool {
850851
telemetry, err = usmhttp2.Spec.Instance.(*usmhttp2.Protocol).GetHTTP2KernelTelemetry()
851852
require.NoError(t, err)
852-
return reflect.DeepEqual(tt.expectedTelemetry, telemetry)
853+
854+
return telemetry.Request_seen == tt.expectedTelemetry.Request_seen &&
855+
telemetry.Response_seen == tt.expectedTelemetry.Response_seen &&
856+
telemetry.Path_exceeds_frame == tt.expectedTelemetry.Path_exceeds_frame &&
857+
telemetry.Exceeding_max_interesting_frames == tt.expectedTelemetry.Exceeding_max_interesting_frames &&
858+
telemetry.Exceeding_max_frames_to_filter == tt.expectedTelemetry.Exceeding_max_frames_to_filter &&
859+
telemetry.End_of_stream+telemetry.End_of_stream_rst >= expectedEOSOrRST &&
860+
reflect.DeepEqual(telemetry.Path_size_bucket, tt.expectedTelemetry.Path_size_bucket)
853861
}, time.Second*5, time.Millisecond*100)
854862
if t.Failed() {
855863
t.Logf("expected telemetry: %+v;\ngot: %+v", tt.expectedTelemetry, telemetry)

0 commit comments

Comments
 (0)