MCPcopy
hub / github.com/vouch/vouch-proxy / TestValidateRequestHandlerPerf

Function TestValidateRequestHandlerPerf

handlers/validate_test.go:64–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

62}
63
64func TestValidateRequestHandlerPerf(t *testing.T) {
65 if _, ok := os.LookupEnv("ISTRAVIS"); ok {
66 t.Skip("travis doesn't like perf tests, skipping")
67 }
68 if _, ok := os.LookupEnv("SKIPPERFTEST"); ok {
69 t.Skip("skipping performance tests")
70 }
71
72 setUp("/config/testing/handler_email.yml")
73 user := &structs.User{Username: "testuser", Email: "test@example.com", Name: "Test Name"}
74 tokens := structs.PTokens{}
75 customClaims := structs.CustomClaims{}
76
77 vpjwt, err := jwtmanager.NewVPJWT(*user, customClaims, tokens)
78 assert.NoError(t, err)
79
80 c := &http.Cookie{
81 // Name: cfg.Cfg.Cookie.Name + "_1of1",
82 Name: cfg.Cfg.Cookie.Name,
83 Value: vpjwt,
84 Expires: time.Now().Add(1 * time.Hour),
85 }
86
87 // handler := http.HandlerFunc(ValidateRequestHandler)
88 handler := jwtmanager.JWTCacheHandler(http.HandlerFunc(ValidateRequestHandler))
89 ts := httptest.NewServer(handler)
90 defer ts.Close()
91
92 freq := 1000
93 duration := 5 * time.Second
94
95 rate := vegeta.Rate{Freq: freq, Per: time.Second}
96 h := &http.Header{}
97 h.Add("Cookie", c.String())
98 h.Add("Host", "myapp.example.com")
99 targeter := vegeta.NewStaticTargeter(vegeta.Target{
100 Method: "GET",
101 URL: ts.URL,
102 Header: *h,
103 })
104
105 attacker := vegeta.NewAttacker()
106
107 var metrics vegeta.Metrics
108 mustFail := false
109 for res := range attacker.Attack(targeter, rate, duration, "Big Bang!") {
110 if res.Code != http.StatusOK {
111 t.Logf("/validate perf %d response code %d", res.Seq, res.Code)
112 mustFail = true
113 }
114 metrics.Add(res)
115 }
116 metrics.Close()
117
118 limit := time.Millisecond
119 if mustFail || metrics.Latencies.P95 > limit {
120 t.Logf("99th percentile latencies: %s", metrics.Latencies.P99)
121 t.Logf("95th percentile latencies: %s", metrics.Latencies.P95)

Callers

nothing calls this directly

Calls 3

NewVPJWTFunction · 0.92
JWTCacheHandlerFunction · 0.92
setUpFunction · 0.70

Tested by

no test coverage detected