|
| 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 sql_test |
| 7 | + |
| 8 | +import ( |
| 9 | + "context" |
| 10 | + "fmt" |
| 11 | + "testing" |
| 12 | + |
| 13 | + "github.com/cockroachdb/cockroach/pkg/base" |
| 14 | + "github.com/cockroachdb/cockroach/pkg/testutils" |
| 15 | + "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" |
| 16 | + "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" |
| 17 | + "github.com/cockroachdb/cockroach/pkg/util/leaktest" |
| 18 | + "github.com/cockroachdb/cockroach/pkg/util/log" |
| 19 | + "github.com/cockroachdb/cockroach/pkg/util/randutil" |
| 20 | +) |
| 21 | + |
| 22 | +func TestCheckExternalConnection(t *testing.T) { |
| 23 | + defer leaktest.AfterTest(t)() |
| 24 | + defer log.Scope(t).Close(t) |
| 25 | + |
| 26 | + ctx := context.Background() |
| 27 | + rng, _ := randutil.NewTestRand() |
| 28 | + dir, dirCleanupFn := testutils.TempDir(t) |
| 29 | + defer dirCleanupFn() |
| 30 | + s, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{ |
| 31 | + ExternalIODir: dir, |
| 32 | + }) |
| 33 | + defer s.Stopper().Stop(ctx) |
| 34 | + |
| 35 | + runner := sqlutils.MakeSQLRunner(sqlDB) |
| 36 | + runner.Exec(t, "CREATE EXTERNAL CONNECTION foo_conn AS 'nodelocal://1/foo';") |
| 37 | + query := "CHECK EXTERNAL CONNECTION 'nodelocal://1/foo';" |
| 38 | + // Should execute successfully without a statement timeout. |
| 39 | + runner.Exec(t, query) |
| 40 | + // Run with a random statement timeout which will likely make the query |
| 41 | + // fail. We don't care whether it does nor which error is returned as long |
| 42 | + // as the process doesn't crash. |
| 43 | + runner.Exec(t, fmt.Sprintf("SET statement_timeout='%dms'", rng.Intn(100)+1)) |
| 44 | + _, _ = sqlDB.Exec(query) |
| 45 | +} |
0 commit comments