Skip to content
67 changes: 66 additions & 1 deletion router-tests/protocol/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,66 @@ func BenchmarkSequentialBigCostControl(b *testing.B) {
cfg.CostControl = &config.CostControl{
Enabled: true,
Mode: config.CostControlModeMeasure,
EstimatedListSize: 15,
EstimatedListSize: 5,
ExposeHeaders: true,
}
},
}, func(b *testing.B, xEnv *testenv.Environment) {
b.SetBytes(int64(len(bigEmployeesResponse)))
b.ReportAllocs()
for b.Loop() {
res := xEnv.MakeGraphQLRequestOK(testenv.GraphQLRequest{
Query: bigEmployeesQuery,
})
if len(res.Body) < 3000 {
b.Errorf("unexpected result %q, expecting \n\n%q", res.Body, bigEmployeesResponse)
}
estimated := res.Response.Header.Get(core.CostEstimatedHeader)
require.Equal(b, "4650", estimated)
actual := res.Response.Header.Get(core.CostActualHeader)
require.Equal(b, "189", actual)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
})
}

func BenchmarkSequentialBigNotCached(b *testing.B) {
testenv.Bench(b, &testenv.Config{
ModifyEngineExecutionConfiguration: func(cfg *config.EngineExecutionConfiguration) {
cfg.EnableNormalizationCache = false
cfg.EnableValidationCache = false
cfg.EnablePersistedOperationsCache = false
cfg.ExecutionPlanCacheSize = 0
cfg.OperationHashCacheSize = 0
},
}, func(b *testing.B, xEnv *testenv.Environment) {
b.SetBytes(int64(len(bigEmployeesResponse)))
b.ReportAllocs()
for b.Loop() {
res := xEnv.MakeGraphQLRequestOK(testenv.GraphQLRequest{
Query: bigEmployeesQuery,
})
if len(res.Body) < 3000 {
b.Errorf("unexpected result %q, expecting \n\n%q", res.Body, bigEmployeesResponse)
}
}
})
}

func BenchmarkSequentialBigNotCachedCostControl(b *testing.B) {
testenv.Bench(b, &testenv.Config{
ModifyEngineExecutionConfiguration: func(cfg *config.EngineExecutionConfiguration) {
cfg.EnableNormalizationCache = false
cfg.EnableValidationCache = false
cfg.EnablePersistedOperationsCache = false
cfg.ExecutionPlanCacheSize = 0
cfg.OperationHashCacheSize = 0
},
ModifySecurityConfiguration: func(cfg *config.SecurityConfiguration) {
cfg.CostControl = &config.CostControl{
Enabled: true,
Mode: config.CostControlModeMeasure,
EstimatedListSize: 5,
ExposeHeaders: true,
}
},
}, func(b *testing.B, xEnv *testenv.Environment) {
Expand All @@ -1603,9 +1662,15 @@ func BenchmarkSequentialBigCostControl(b *testing.B) {
res := xEnv.MakeGraphQLRequestOK(testenv.GraphQLRequest{
Query: bigEmployeesQuery,
})
b.StopTimer()
if len(res.Body) < 3000 {
b.Errorf("unexpected result %q, expecting \n\n%q", res.Body, bigEmployeesResponse)
}
estimated := res.Response.Header.Get(core.CostEstimatedHeader)
require.Equal(b, "4650", estimated)
actual := res.Response.Header.Get(core.CostActualHeader)
require.Equal(b, "189", actual)
b.StartTimer()
}
})
}
Expand Down
2 changes: 2 additions & 0 deletions router-tests/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,15 @@ func Bench(b *testing.B, cfg *Config, f func(b *testing.B, xEnv *Environment)) {
}
b.StartTimer()
f(b, env)
b.StopTimer()
if cfg.AssertCacheMetrics != nil {
assertCacheMetrics(b, env, cfg.AssertCacheMetrics.BaseGraphAssertions, "")

for ff, v := range cfg.AssertCacheMetrics.FeatureFlagAssertions {
assertCacheMetrics(b, env, v, ff)
}
}
b.StartTimer()
}

const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Expand Down
Loading