Skip to content

Commit 888c835

Browse files
pr feedback
1 parent 0c22d80 commit 888c835

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

test/e2e/chromesandbox_claim_test.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 The Kubernetes Authors.
1+
// Copyright 2026 The Kubernetes Authors.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"os"
2121
"strconv"
22+
"sync"
2223
"sync/atomic"
2324
"testing"
2425
"time"
@@ -97,23 +98,38 @@ func BenchmarkChromeSandboxClaimStartup(b *testing.B) {
9798
b.Fatalf("WarmPool failed to become ready: %v", err)
9899
}
99100
b.Logf("WarmPool is ready.")
101+
var (
102+
mu sync.Mutex
103+
totalClaimCreatedSec float64
104+
totalClaimReadySec float64
105+
totalClaims int
106+
)
100107

101108
// 5. Benchmark Loop
102109
b.SetParallelism(parallelism)
103110
b.ResetTimer()
104111

105112
b.RunParallel(func(pb *testing.PB) {
106113
for pb.Next() {
107-
metrics := runChromeSandboxClaim(tc, ns.Name, template.Name)
108-
109-
// Record metrics
110-
b.ReportMetric(metrics.ClaimCreated.Seconds(), "claim-created-sec")
111-
b.ReportMetric(metrics.ClaimReady.Seconds(), "claim-ready-sec")
114+
metrics, err := runChromeSandboxClaim(tc, ns.Name, template.Name)
115+
116+
if err == nil {
117+
mu.Lock()
118+
totalClaimCreatedSec += metrics.ClaimCreated.Seconds()
119+
totalClaimReadySec += metrics.ClaimReady.Seconds()
120+
totalClaims++
121+
mu.Unlock()
122+
}
112123
}
113124
})
125+
126+
if totalClaims > 0 {
127+
b.ReportMetric(totalClaimCreatedSec/float64(totalClaims), "claim-created-sec/op")
128+
b.ReportMetric(totalClaimReadySec/float64(totalClaims), "claim-ready-sec/op")
129+
}
114130
}
115131

116-
func runChromeSandboxClaim(tc *framework.TestContext, namespace, templateName string) *ChromeSandboxClaimMetrics {
132+
func runChromeSandboxClaim(tc *framework.TestContext, namespace, templateName string) (*ChromeSandboxClaimMetrics, error) {
117133
metrics := &ChromeSandboxClaimMetrics{}
118134

119135
// Unique name for this claim
@@ -133,7 +149,7 @@ func runChromeSandboxClaim(tc *framework.TestContext, namespace, templateName st
133149
// Use a background context for cleanup actions, but the test context for operations
134150
if err := tc.ClusterClient.Create(tc.Context(), claim); err != nil {
135151
tc.Logf("Failed to create claim %s: %v", claimName, err)
136-
return metrics
152+
return metrics, err
137153
}
138154
metrics.ClaimCreated.Set(time.Since(startTime))
139155
tc.Logf("Created claim %s", claimName)
@@ -147,12 +163,12 @@ func runChromeSandboxClaim(tc *framework.TestContext, namespace, templateName st
147163
// We use the common predicates
148164
if err := tc.WaitForObject(tc.Context(), claim, predicates.ReadyConditionIsTrue); err != nil {
149165
tc.Logf("Failed to wait for claim %s ready: %v", claimName, err)
150-
return metrics
166+
return metrics, err
151167
}
152168
metrics.ClaimReady.Set(time.Since(startTime))
153169
tc.Logf("Claim %s is ready", claimName)
154170

155-
return metrics
171+
return metrics, nil
156172
}
157173

158174
var claimCounter int64

0 commit comments

Comments
 (0)