Skip to content

Commit f719ee1

Browse files
committed
logictest: rename setUser to setSessionUser
This makes it clear that the "current user" can still be modified if one executes SET ROLE commands in a logic test. Release note: None
1 parent 353c2ca commit f719ee1

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pkg/sql/logictest/logic.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ type logicTest struct {
10001000
clients map[string]map[int]*gosql.DB
10011001
// client currently in use. This can change during processing
10021002
// of a test input file when encountering the "user" directive.
1003-
// see setUser() for details.
1003+
// see setSessionUser() for details.
10041004
user string
10051005
db *gosql.DB
10061006
// clusterCleanupFuncs contains the cleanup methods that are specific to a
@@ -1168,9 +1168,9 @@ func (t *logicTest) outf(format string, args ...interface{}) {
11681168
fmt.Printf("[%s] %s\n", now, msg)
11691169
}
11701170

1171-
// setUser sets the DB client to the specified user and connects
1171+
// setSessionUser sets the DB client to the specified user and connects
11721172
// to the node in the cluster at index nodeIdx.
1173-
func (t *logicTest) setUser(user string, nodeIdx int) {
1173+
func (t *logicTest) setSessionUser(user string, nodeIdx int) {
11741174
db := t.getOrOpenClient(user, nodeIdx)
11751175
t.db = db
11761176
t.user = user
@@ -1308,7 +1308,7 @@ func (t *logicTest) newTestServerCluster(bootstrapBinaryPath, upgradeBinaryPath
13081308
t.testserverCluster = ts
13091309
t.clusterCleanupFuncs = append(t.clusterCleanupFuncs, ts.Stop, cleanupLogsDir)
13101310

1311-
t.setUser(username.RootUser, 0 /* nodeIdx */)
1311+
t.setSessionUser(username.RootUser, 0 /* nodeIdx */)
13121312
}
13131313

13141314
// newCluster creates a new cluster. It should be called after the logic tests's
@@ -1759,7 +1759,7 @@ func (t *logicTest) newCluster(
17591759
)
17601760
}
17611761

1762-
t.setUser(username.RootUser, 0 /* nodeIdx */)
1762+
t.setSessionUser(username.RootUser, 0 /* nodeIdx */)
17631763
}
17641764

17651765
// waitForTenantReadOnlyClusterSettingToTakeEffectOrFatal waits until all tenant
@@ -2258,7 +2258,7 @@ func (t *logicTest) maybeBackupRestore(
22582258
oldUser := t.user
22592259
oldNodeIdx := t.nodeIdx
22602260
defer func() {
2261-
t.setUser(oldUser, oldNodeIdx)
2261+
t.setSessionUser(oldUser, oldNodeIdx)
22622262
}()
22632263

22642264
log.Info(context.Background(), "Running cluster backup and restore")
@@ -2278,7 +2278,7 @@ func (t *logicTest) maybeBackupRestore(
22782278
userToSessionVars[user] = make(map[int]map[string]string)
22792279
for nodeIdx := range userClients {
22802280
users[user] = append(users[user], nodeIdx)
2281-
t.setUser(user, nodeIdx)
2281+
t.setSessionUser(user, nodeIdx)
22822282

22832283
// Serialize session variables.
22842284
var userSession string
@@ -2320,7 +2320,7 @@ func (t *logicTest) maybeBackupRestore(
23202320
bucket, strconv.FormatInt(timeutil.Now().UnixNano(), 10))
23212321

23222322
// Perform the backup and restore as root.
2323-
t.setUser(username.RootUser, 0 /* nodeIdx */)
2323+
t.setSessionUser(username.RootUser, 0 /* nodeIdx */)
23242324

23252325
if _, err := t.db.Exec(fmt.Sprintf("BACKUP INTO '%s'", backupLocation)); err != nil {
23262326
return errors.Wrap(err, "backing up cluster")
@@ -2331,7 +2331,7 @@ func (t *logicTest) maybeBackupRestore(
23312331
t.resetCluster()
23322332

23332333
// Run the restore as root.
2334-
t.setUser(username.RootUser, 0 /* nodeIdx */)
2334+
t.setSessionUser(username.RootUser, 0 /* nodeIdx */)
23352335
if _, err := t.db.Exec(fmt.Sprintf("RESTORE FROM LATEST IN '%s'", backupLocation)); err != nil {
23362336
return errors.Wrap(err, "restoring cluster")
23372337
}
@@ -2343,7 +2343,7 @@ func (t *logicTest) maybeBackupRestore(
23432343
for user, userNodeIdxs := range users {
23442344
for _, nodeIdx := range userNodeIdxs {
23452345
// Call setUser for every user to create the connection for that user.
2346-
t.setUser(user, nodeIdx)
2346+
t.setSessionUser(user, nodeIdx)
23472347

23482348
if userSession, ok := userToHexSession[user][nodeIdx]; ok {
23492349
if _, err := t.db.Exec(fmt.Sprintf(`SELECT crdb_internal.deserialize_session(decode('%s', 'hex'))`, userSession)); err != nil {
@@ -2990,7 +2990,7 @@ func (t *logicTest) processSubtest(
29902990
nodeIdx = int(idx)
29912991
}
29922992
}
2993-
t.setUser(fields[1], nodeIdx)
2993+
t.setSessionUser(fields[1], nodeIdx)
29942994
// In multi-tenant tests, we may need to also create database test when
29952995
// we switch to a different tenant.
29962996
//
@@ -3120,7 +3120,7 @@ func (t *logicTest) processSubtest(
31203120
// If we upgraded the node we are currently on, we need to open a new
31213121
// connection since the previous one might now be invalid.
31223122
if t.nodeIdx == nodeIdx {
3123-
t.setUser(t.user, nodeIdx)
3123+
t.setSessionUser(t.user, nodeIdx)
31243124
}
31253125
default:
31263126
return errors.Errorf("%s:%d: unknown command: %s",
@@ -3819,7 +3819,7 @@ func (t *logicTest) validateAfterTestCompletion() error {
38193819
}
38203820
delete(t.clients, user)
38213821
}
3822-
t.setUser(username.RootUser, 0 /* nodeIdx */)
3822+
t.setSessionUser(username.RootUser, 0 /* nodeIdx */)
38233823

38243824
// Some cleanup to make sure the following validation queries can run
38253825
// successfully. First we rollback in case the logic test had an uncommitted

0 commit comments

Comments
 (0)