Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multitenant: deflake TestConsumption #105552

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions pkg/ccl/multitenantccl/tenantcostclient/tenant_side_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,9 @@ func TestConsumption(t *testing.T) {
hostServer, _, _ := serverutils.StartServer(t, base.TestServerArgs{DefaultTestTenant: base.TestControlsTenantsExplicitly})
defer hostServer.Stopper().Stop(context.Background())

const targetPeriod = time.Millisecond
st := cluster.MakeTestingClusterSettings()
tenantcostclient.TargetPeriodSetting.Override(context.Background(), &st.SV, time.Millisecond)
tenantcostclient.TargetPeriodSetting.Override(context.Background(), &st.SV, targetPeriod)
tenantcostclient.CPUUsageAllowance.Override(context.Background(), &st.SV, 0)

testProvider := newTestProvider()
Expand Down Expand Up @@ -902,21 +903,32 @@ func TestConsumption(t *testing.T) {
r.Exec(t, "INSERT INTO t (v) SELECT repeat('1234567890', 1024) FROM generate_series(1, 10) AS g(i)")
const expectedBytes = 10 * 10 * 1024

afterWrite := testProvider.waitForConsumption(t)
delta := afterWrite
delta.Sub(&beforeWrite)
if delta.WriteBatches < 1 || delta.WriteRequests < 2 || delta.WriteBytes < expectedBytes*2 {
t.Errorf("usage after write: %s", delta.String())
}
// Try a few times because background activity can trigger bucket
// requests before the test query does.
testutils.SucceedsSoon(t, func() error {
afterWrite := testProvider.waitForConsumption(t)
delta := afterWrite
delta.Sub(&beforeWrite)
if delta.WriteBatches < 1 || delta.WriteRequests < 2 || delta.WriteBytes < expectedBytes*2 {
return errors.Newf("usage after write: %s", delta.String())
}
return nil
})

beforeRead := testProvider.waitForConsumption(t)
r.QueryStr(t, "SELECT min(v) FROM t")

afterRead := testProvider.waitForConsumption(t)
delta = afterRead
delta.Sub(&afterWrite)
if delta.ReadBatches < 1 || delta.ReadRequests < 1 || delta.ReadBytes < expectedBytes {
t.Errorf("usage after read: %s", delta.String())
}
// Try a few times because background activity can trigger bucket
// requests before the test query does.
testutils.SucceedsSoon(t, func() error {
afterRead := testProvider.waitForConsumption(t)
delta := afterRead
delta.Sub(&beforeRead)
if delta.ReadBatches < 1 || delta.ReadRequests < 1 || delta.ReadBytes < expectedBytes {
return errors.Newf("usage after read: %s", delta.String())
}
return nil
})
r.Exec(t, "DELETE FROM t WHERE true")
}
// Make sure some CPU usage is reported.
Expand Down