Skip to content

Commit 16a5d5c

Browse files
committed
ci: make upstream benchmark harness compatible with old/new resolver layouts
1 parent 0500fa4 commit 16a5d5c

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

scripts/ci/benchmarks/component/dns/upstream_hotpath_bench_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,30 @@ func benchmarkInitializedResolver(b *testing.B) *UpstreamResolver {
3737
if !stateField.IsValid() {
3838
b.Fatalf("unsupported UpstreamResolver layout")
3939
}
40-
store := stateField.Addr().MethodByName("Store")
41-
if !store.IsValid() || store.Type().NumIn() != 1 {
42-
b.Fatalf("state.Store method unavailable")
40+
// atomic.Pointer[T] internals: write pointer directly into field "v".
41+
vField := stateField.FieldByName("v")
42+
if !vField.IsValid() {
43+
b.Fatalf("atomic pointer backing field not found")
4344
}
44-
statePtrType := store.Type().In(0) // *upstreamState
45-
state := reflect.New(statePtrType.Elem())
45+
if vField.Type().Kind() != reflect.UnsafePointer {
46+
b.Fatalf("unexpected atomic backing field type: %v", vField.Type())
47+
}
48+
// Derive *upstreamState type from stateField methods.
49+
load := stateField.Addr().MethodByName("Load")
50+
if !load.IsValid() || load.Type().NumOut() != 1 {
51+
b.Fatalf("state.Load method unavailable")
52+
}
53+
upstreamStatePtrType := load.Type().Out(0)
54+
if upstreamStatePtrType.Kind() != reflect.Pointer {
55+
b.Fatalf("unexpected Load output type: %v", upstreamStatePtrType)
56+
}
57+
state := reflect.New(upstreamStatePtrType.Elem())
4658
stateUpstreamField := state.Elem().FieldByName("upstream")
4759
if !stateUpstreamField.IsValid() {
4860
b.Fatalf("upstreamState.upstream field missing")
4961
}
5062
setField(stateUpstreamField, reflect.ValueOf(up))
51-
store.Call([]reflect.Value{state})
63+
setField(vField, reflect.ValueOf(unsafe.Pointer(state.Pointer())))
5264
return r
5365
}
5466

0 commit comments

Comments
 (0)