|
| 1 | +// Copyright 2025 The Cockroach Authors. |
| 2 | +// |
| 3 | +// Use of this software is governed by the CockroachDB Software License |
| 4 | +// included in the /LICENSE file. |
| 5 | + |
| 6 | +package structlogging_test |
| 7 | + |
| 8 | +import ( |
| 9 | + "context" |
| 10 | + "testing" |
| 11 | + |
| 12 | + "github.com/cockroachdb/cockroach/pkg/base" |
| 13 | + "github.com/cockroachdb/cockroach/pkg/jobs" |
| 14 | + "github.com/cockroachdb/cockroach/pkg/testutils" |
| 15 | + "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" |
| 16 | + "github.com/cockroachdb/cockroach/pkg/testutils/skip" |
| 17 | + "github.com/cockroachdb/cockroach/pkg/util/leaktest" |
| 18 | + "github.com/cockroachdb/cockroach/pkg/util/log" |
| 19 | + "github.com/cockroachdb/errors" |
| 20 | + "github.com/stretchr/testify/require" |
| 21 | +) |
| 22 | + |
| 23 | +// This test verifies that the hot ranges logging job starts for both |
| 24 | +// the system and app layers, and exits quickly for the system layer. |
| 25 | +func TestHotRangesLoggingJobExitProcedure(t *testing.T) { |
| 26 | + defer leaktest.AfterTest(t)() |
| 27 | + defer log.Scope(t).Close(t) |
| 28 | + skip.UnderStress(t) |
| 29 | + skip.UnderRace(t) |
| 30 | + |
| 31 | + ctx := context.Background() |
| 32 | + ts := serverutils.StartServerOnly(t, base.TestServerArgs{ |
| 33 | + Knobs: base.TestingKnobs{ |
| 34 | + JobsTestingKnobs: jobs.NewTestingKnobsWithShortIntervals(), |
| 35 | + }, |
| 36 | + }) |
| 37 | + defer ts.Stopper().Stop(ctx) |
| 38 | + |
| 39 | + syslayer := ts.SystemLayer().SQLConn(t) |
| 40 | + applayer := ts.ApplicationLayer().SQLConn(t) |
| 41 | + |
| 42 | + testutils.SucceedsSoon(t, func() error { |
| 43 | + row := syslayer.QueryRow("SELECT status FROM system.public.jobs WHERE id = $1", jobs.HotRangesLoggerJobID) |
| 44 | + var status string |
| 45 | + require.NoError(t, row.Scan(&status)) |
| 46 | + if status != "succeeded" { |
| 47 | + return errors.Newf("system job status is %s, not succeeded", status) |
| 48 | + } |
| 49 | + |
| 50 | + row = applayer.QueryRow("SELECT status FROM system.public.jobs WHERE id = $1", jobs.HotRangesLoggerJobID) |
| 51 | + require.NoError(t, row.Scan(&status)) |
| 52 | + if status != "running" { |
| 53 | + return errors.Newf("app job status is %s, not running", status) |
| 54 | + } |
| 55 | + return nil |
| 56 | + }) |
| 57 | +} |
0 commit comments