Skip to content

Commit

Permalink
usm: tests: http2: Fix a bug in debug output of a test (#21469)
Browse files Browse the repository at this point in the history
* usm: tests: http2: Fix a bug in debug output of a test

The PR fixes a bug in the test debug log (when the test fails)
Also, the PR moves out from the test, the generation of expected results for the tests

* Update monitor_test.go
  • Loading branch information
guyarb authored Dec 11, 2023
1 parent c61bbc2 commit 45c774d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions pkg/network/usm/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,24 +664,30 @@ func (s *USMHTTP2Suite) TestHTTP2ManyDifferentPaths() {
}
}

func (s *USMHTTP2Suite) TestSimpleHTTP2() {
t := s.T()
cfg := networkconfig.New()
cfg.EnableHTTP2Monitoring = true

startH2CServer(t)

func getExpectedOutcomeForPathWithRepeatedChars() map[http.Key]captureRange {
expected := make(map[http.Key]captureRange)
// currently we have a bug with paths which are not Huffman encoded, therefore, we are skipping them by starting from `/aaa` (i := 3).
// The path `/a` and `/aa` are not being encoded with Huffman, and that's an edge case for our http2 monitoring for the moment,
// thus we're starting with `/aaa` and above.
for i := 3; i < 100; i++ {
expected[http.Key{
Path: http.Path{Content: http.Interner.GetString(fmt.Sprintf("/%s", strings.Repeat("a", i)))},
Path: http.Path{
Content: http.Interner.GetString(fmt.Sprintf("/%s", strings.Repeat("a", i))),
},
Method: http.MethodPost,
}] = captureRange{
lower: 1,
upper: 1,
}
}
return expected
}

func (s *USMHTTP2Suite) TestSimpleHTTP2() {
t := s.T()
cfg := networkconfig.New()
cfg.EnableHTTP2Monitoring = true

startH2CServer(t)

tests := []struct {
name string
Expand Down Expand Up @@ -746,7 +752,7 @@ func (s *USMHTTP2Suite) TestSimpleHTTP2() {
req.Body.Close()
}
},
expectedEndpoints: expected,
expectedEndpoints: getExpectedOutcomeForPathWithRepeatedChars(),
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -800,7 +806,7 @@ func (s *USMHTTP2Suite) TestSimpleHTTP2() {
return true
}, time.Second*5, time.Millisecond*100, "%v != %v", res, tt.expectedEndpoints)
if t.Failed() {
for key := range expected {
for key := range tt.expectedEndpoints {
if _, ok := res[key]; !ok {
t.Logf("key: %v was not found in res", key.Path.Content.Get())
}
Expand Down

0 comments on commit 45c774d

Please sign in to comment.