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)
| 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). |
| 139 | func 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 | |
| 167 | func TestResolveModelAlias(t *testing.T) { |
| 168 | t.Parallel() |
nothing calls this directly
no test coverage detected