Skip to content

Commit 6e0dfb1

Browse files
craig[bot]knz
craig[bot]
andcommitted
Merge #109993
109993: serverutils: better doc the TestServerInterface r=stevendanna,herkolategan a=knz This PR goes hand-in-hand with the following new doc page, which should be reviewed as well: https://cockroachlabs.atlassian.net/wiki/spaces/CRDB/pages/3155427384/TestServer+and+TestCluster Epic: CRDB-18499 Release note: None Co-authored-by: Raphael 'kena' Poss <[email protected]>
2 parents 8ee0bc7 + 6beb14c commit 6e0dfb1

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

pkg/testutils/serverutils/api.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,15 @@ type TestServerInterface interface {
6565

6666
// ApplicationLayerInterface is implemented by TestServerInterface
6767
// for backward-compatibility with existing test code.
68-
// New code should spell out their intent clearly by calling
69-
// the .ApplicationLayer() or .SystemLayer() methods directly.
68+
//
69+
// It is CURRENTLY equivalent to .SystemLayer() however this is
70+
// a misdesign and results in poor test semantics.
71+
//
72+
// See: https://go.crdb.dev/p/testserver-api-problem
73+
//
74+
// New tests should spell out their intent clearly by calling the
75+
// .ApplicationLayer() (preferred) or .SystemLayer() methods
76+
// directly.
7077
ApplicationLayerInterface
7178

7279
// TenantControlInterface is implemented by TestServerInterface
@@ -78,7 +85,7 @@ type TestServerInterface interface {
7885
// ApplicationLayer returns the interface to the application layer that is
7986
// exercised by the test. Depending on how the test server is started
8087
// and (optionally) randomization, this can be either the SQL layer
81-
// of a secondary tenant or that of the system tenant.
88+
// of a virtual cluster or that of the system interface.
8289
ApplicationLayer() ApplicationLayerInterface
8390

8491
// SystemLayer returns the interface to the application layer
@@ -137,8 +144,7 @@ type TestServerController interface {
137144

138145
// ApplicationLayerInterface defines accessors to the application
139146
// layer of a test server. Tests written against this interface are
140-
// effectively agnostic to whether they use a secondary tenant or not.
141-
// This interface is implemented by server.Test{Tenant,Server}.
147+
// effectively agnostic to whether they use a virtual cluster or not.
142148
type ApplicationLayerInterface interface {
143149
// Readiness returns true when the server is ready, that is,
144150
// when it is accepting connections and it is not draining.
@@ -458,7 +464,7 @@ type ApplicationLayerInterface interface {
458464
// start the SQL and HTTP service for secondary tenants (virtual
459465
// clusters).
460466
type TenantControlInterface interface {
461-
// StartSharedProcessTenant starts the service for a secondary tenant
467+
// StartSharedProcessTenant starts the service for a virtual cluster
462468
// using the special configuration we define for shared-process deployments.
463469
//
464470
// args.TenantName must be specified. If a tenant with that name already
@@ -473,7 +479,7 @@ type TenantControlInterface interface {
473479
ctx context.Context, args base.TestSharedProcessTenantArgs,
474480
) (ApplicationLayerInterface, *gosql.DB, error)
475481

476-
// StartTenant starts the service for a secondary tenant using the special
482+
// StartTenant starts the service for a virtual cluster using the special
477483
// configuration we define for separate-process deployments. This incidentally
478484
// is also the configuration we use in CC Serverless.
479485
//

pkg/testutils/serverutils/conditional_wrap.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,12 @@ import (
2121
)
2222

2323
const tipText = `consider replacing the test server initialization from:
24-
25-
ts, db, kvDB := serverutils.StartServer(t, ...)
26-
// or:
27-
tc := serverutils.StartCluster(t, ...)
28-
ts := tc.Server(0)
29-
30-
To:
31-
32-
srv, db, kvDB := serverutils.StartServer(t, ...)
33-
defer srv.Stop(...)
24+
ts, ... := serverutils.StartServer(t, ...)
25+
defer ts.Stopper().Stop(...)
26+
to:
27+
srv, ... := serverutils.StartServer(t, ...)
28+
defer srv.Stopper().Stop(...)
3429
ts := srv.ApplicationLayer()
35-
// or:
36-
tc := serverutils.StartCluster(t, ...)
37-
ts := tc.Server(0).ApplicationLayer()
38-
3930
`
4031

4132
// When this env var is set, all the suspicious API calls are reported in test logs.
@@ -224,7 +215,9 @@ func makeSeriousNotifyFn(
224215
}
225216
return func(methodName string) {
226217
reportFn(func() {
227-
(*logFn)("\n%s\n\tWARNING: risky use of implicit %s via .%s()\nHINT: clarify intent using .%s().%s() or .%s().%s() instead.\n",
218+
(*logFn)("\n%s\n\tWARNING: risky use of implicit %s via .%s()\n"+
219+
"See: https://go.crdb.dev/p/testserver-api-problem\n"+
220+
"HINT: clarify intent using .%s().%s() or .%s().%s() instead.\n",
228221
GetExternalCaller(),
229222
ifname, methodName, accessor1, methodName, accessor2, methodName)
230223
(*logFn)("TIP: %s", tipText)

pkg/testutils/serverutils/conditional_wrap_internal_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ func TestBenignNotifyFn(t *testing.T) {
3838
fn("foo")
3939
fn("foo")
4040
result := buf.String()
41-
require.Contains(t, result, "NOTICE: .foo() called via implicit interface IN;\nHINT: consider using .ACC().foo() instead")
41+
require.Contains(t, result, "NOTICE: .foo() called via implicit interface IN")
42+
require.Contains(t, result, "HINT: consider using .ACC().foo() instead")
4243
if showTip {
4344
require.Contains(t, result, "TIP:")
4445
} else {
@@ -71,7 +72,8 @@ func TestSeriousNotifyFn(t *testing.T) {
7172
fn("foo")
7273
fn("foo")
7374
result := buf.String()
74-
require.Contains(t, result, "WARNING: risky use of implicit IN via .foo()\nHINT: clarify intent using .ACC1().foo() or .ACC2().foo() instead")
75+
require.Contains(t, result, "WARNING: risky use of implicit IN via .foo()")
76+
require.Contains(t, result, "HINT: clarify intent using .ACC1().foo() or .ACC2().foo() instead")
7577
require.Contains(t, result, "TIP:")
7678

7779
if reportAllCalls {

0 commit comments

Comments
 (0)