MCPcopy Index your code
hub / github.com/docker/docker-agent / BenchmarkGetModelFetchDisallowed

Function BenchmarkGetModelFetchDisallowed

pkg/modelsdev/store_test.go:139–165  ·  view source on GitHub ↗

BenchmarkGetModelFetchDisallowed guards the hot path: repeatedly resolving a fetch-disallowed provider against a warm, sizable cache must not re-read and re-parse the catalog file each call (the snapshot is memoized).

(b *testing.B)

Source from the content-addressed store, hash-verified

137// fetch-disallowed provider against a warm, sizable cache must not re-read and
138// re-parse the catalog file each call (the snapshot is memoized).
139func BenchmarkGetModelFetchDisallowed(b *testing.B) {
140 cacheFile := filepath.Join(b.TempDir(), "models_dev.json")
141 providers := make(map[string]Provider, 200)
142 for i := range 200 {
143 models := make(map[string]Model, 50)
144 for j := range 50 {
145 id := fmt.Sprintf("m-%d-%d", i, j)
146 models[id] = Model{Name: id, Limit: Limit{Context: 128000}}
147 }
148 providers[fmt.Sprintf("prov-%d", i)] = Provider{Models: models}
149 }
150 writeCache(b, cacheFile, Database{Providers: providers})
151
152 store, err := NewStore(
153 WithCache(cacheFile),
154 WithKnownProvider(func(p string) bool { return p == "openai" }),
155 )
156 require.NoError(b, err)
157
158 id := NewID("mistral_gateway", "whatever")
159 ctx := b.Context()
160 b.ReportAllocs()
161 b.ResetTimer()
162 for range b.N {
163 _, _ = store.GetModel(ctx, id)
164 }
165}
166
167func TestResolveModelAlias(t *testing.T) {
168 t.Parallel()

Callers

nothing calls this directly

Calls 7

GetModelMethod · 0.95
writeCacheFunction · 0.85
WithKnownProviderFunction · 0.85
NewIDFunction · 0.85
ContextMethod · 0.80
NewStoreFunction · 0.70
WithCacheFunction · 0.70

Tested by

no test coverage detected