Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
106769: tenantcostclient: tighten query RU estimate test r=yuzefovich a=yuzefovich

The query RU estimate test involves two runs of test queries:
- via EXPLAIN ANALYZE to get the RU estimate
- "vanilla" way and getting the precise RU usage.

One of the test queries is a large INSERT, and previously we didn't delete the data after the first run. As a result, the second run would operate on 2x size of the data set. This commit fixes that oversight by including a DELETE query into the test query set which allows us to tighten the delta margin from 0.75 to 0.05 (got no failures in over 1k runs with 0.05 now).

Epic: None

Release note: None

Co-authored-by: Yahor Yuzefovich <[email protected]>
  • Loading branch information
craig[bot] and yuzefovich committed Jul 13, 2023
2 parents ff5f220 + 73f2374 commit b6b5d28
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func TestEstimateQueryRUConsumption(t *testing.T) {
sql: "SELECT 'deadbeef' FROM generate_series(1, 50000)",
count: 10,
},
{ // Delete (this also ensures that two runs work with the same dataset)
sql: "DELETE FROM abcd WHERE true",
count: 1,
},
}

var err error
Expand Down Expand Up @@ -191,12 +195,7 @@ func TestEstimateQueryRUConsumption(t *testing.T) {
// Check the estimated RU aggregate for all the queries against the actual
// measured RU consumption for the tenant.
tenantMeasuredRUs = getTenantRUs() - tenantStartRUs
// Usually, the difference is within 0.25 delta, but in rare cases it can be
// outside of that delta (when ran on the gceworker, it was outside the 0.5
// delta within 6 minutes of stressing), so we allow for generous 0.75
// delta. This still provides a good enough sanity check for the RU
// estimation.
const deltaFraction = 0.75
const deltaFraction = 0.05
allowedDelta := tenantMeasuredRUs * deltaFraction
require.InDeltaf(t, tenantMeasuredRUs, tenantEstimatedRUs, allowedDelta,
"estimated RUs (%d) were not within %f RUs of the expected value (%f)",
Expand Down

0 comments on commit b6b5d28

Please sign in to comment.