Skip to content

Commit

Permalink
usm: http2: Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
guyarb committed Nov 17, 2023
1 parent f5545b3 commit b056410
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions pkg/network/usm/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,59 @@ func TestHTTP2(t *testing.T) {
})
}

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

startH2CServer(t)

monitor, err := NewMonitor(cfg, nil, nil, nil)
require.NoError(t, err)
require.NoError(t, monitor.Start())
defer monitor.Stop()

// Should be bigger than the length of the http2_dynamic_table which is 1024
numberOfRequests := 1500
clients := getClientsArray(t, 1)
for i := 0; i < numberOfRequests; i++ {
for j := 0; j < 2; j++ {
req, err := clients[0].Post(fmt.Sprintf("%s/test-%d", http2SrvAddr, i+1), "application/json", bytes.NewReader([]byte("test")))
require.NoError(t, err, "could not make request")
req.Body.Close()
}
}

matches := PrintableInt(0)

seenRequests := map[string]int{}
assert.Eventuallyf(t, func() bool {
stats := monitor.GetProtocolStats()
http2Stats, ok := stats[protocols.HTTP2]
if !ok {
return false
}
http2StatsTyped := http2Stats.(map[http.Key]*http.RequestStats)
for key, stat := range http2StatsTyped {
if (key.DstPort == http2SrvPort || key.SrcPort == http2SrvPort) && key.Method == http.MethodPost && strings.HasPrefix(key.Path.Content.Get(), "/test") {
if _, ok := seenRequests[key.Path.Content.Get()]; !ok {
seenRequests[key.Path.Content.Get()] = 0
}
seenRequests[key.Path.Content.Get()] += stat.Data[200].Count
matches.Add(stat.Data[200].Count)
}
}

return matches.Load() == 2*numberOfRequests
}, time.Second*10, time.Millisecond*100, "%v != %v", &matches, 2*numberOfRequests)

for i := 0; i < numberOfRequests; i++ {
if v, ok := seenRequests[fmt.Sprintf("/test-%d", i+1)]; !ok || v != 2 {
t.Logf("path: /test-%d should have 2 occurrences but instead has %d", i+1, v)
}
}
}

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

0 comments on commit b056410

Please sign in to comment.