Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
84364: test: enforce skip.UnderStress[Race] locally r=[rickystewart] a=HonoreDB

Fixes #84312

Previously, skip.UnderStress only checked NightlyStress(),
which is only set during nightly stress test runs, not
by ./dev test --stress or make stress. This lead to
developers checking in tests that flake or reliably fail
under stress or stressrace.

This PR modifies dev and make to set a COCKROACH_STRESS
environment variable, and modifies skip to honor both
that flag and the one set by nightly stress.

A follow-up might be to default to not skipping when
a filter matches only one test, as there the intent was
almost certainly to actually run it.

Release note: None

84532: cli,sdnotify: improve the handling of unix socket directories r=jreut a=knz

tldr: This patch makes it easier for users to understand when
CockroachDB has a problem using/creating unix sockets, and
what they can do to avert the situation.

Fixes #76904.

Example, before;
```
$ cockroach start-single-node --insecure --background
...
listen unixgram /data/home/kena/cockroach/this-is-a-very-long-directory-name-the-point-is-to-be-more-than-one-hundred-and-twenty-three-characters/sdnotify2139543236/notify.sock: bind: invalid argument
```

Example, after:
```
$ cockroach start-single-node --insecure --background
ERROR: no suitable directory found for the --background notify socket
HINT: Avoid using --background altogether (preferred), or use a
shorter directory name for --socket-dir, TMPDIR or the current directory.
```

**Context:**

CockroachDB uses unix sockets both to handle `--background` and to
create a postgres-compatible SQL client socket via `--socket-dir`. For
`--background`, the logic was previously hardwired to always use
`os.TempDir()`, i.e. either `$TMPDIR` or `/tmp`.

On Unix, socket objects are commonly limited to 128 bytes;
that's e.g. 104 path characters including final NUL on BSD, 108 on glibc.
When the actual length is larger, creating the socket fails with
a confusing error `bind: invalid argument`.

**The problem:**

Users have reported issues in the following circumstances:

- when setting their CWD/$TMPDIR to a long directory name,
  they expected `--socket-dir` to also influence the socket
  name used for `--background`. Instead, `--background`
  failed with a hard-to-understand error. (#76904)

- when running tests inside a container/sandbox with a long
  prefix, they were confused that `--background` / `--socket-dir=.`
  did not work properly.

- they use macOS which has very large directory names in $TMPDIR.

To improve user experience, this patch changes the behavior
as described in the release notes below below.

Release note (cli change): CockroachDB now produces a clearer error
when the path specified via `--socket-dir` is too long.

Release note (cli change): When the flag `--background` is specified,
CockroachDB now makes 3 attempts to find a suitable directory to
create the notification socket: the value of `--socket-dir` if
specified, the value of `$TMPDIR` (or /tmp if the env var is empty),
and the current working directory. If none of these directories has a
name short enough, an explanatory error is printed.

84649: cluster-ui: allow dynamic timescale window from key buttons r=maryliag a=xinhaoz

fixes #77007

Previously, controlling the time scale window using the arrow
key buttons and 'Now' button would disable the dynamically moving
window even when the end time = now. This commit makes it so that
when the time window is changed to include the current time (i.e.
endTime = now), the time window will be changed to dynamic to
ensure the window is keep up to date with the current time.

This commit also fixes the object construction of the time scale
from session storage and corrects the 'Now' button tooltip label from
'past 1 day' to 'Most recent interval'.

Release note (bug fix): changing the time window using arrow buttons
and 'Now' button will now properly turn the timeframe into a moving
window when endTime = now.

https://www.loom.com/share/54d65c04580747dc92f7e4976b953be6

84667: ci: only build `roachprod` on Unix r=jlinder a=rickystewart

This fails to build on Windows which was breaking CI.

Release note: None

Co-authored-by: Aaron Zinger <[email protected]>
Co-authored-by: Raphael 'kena' Poss <[email protected]>
Co-authored-by: Xin Hao Zhang <[email protected]>
Co-authored-by: Ricky Stewart <[email protected]>
  • Loading branch information
5 people committed Jul 19, 2022
5 parents 6e9f5a9 + 393120d + 82d92c5 + 7377c2b + 024b27a commit 477644e
Show file tree
Hide file tree
Showing 28 changed files with 281 additions and 96 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1154,10 +1154,10 @@ check test testshort testrace testdeadlock bench benchshort:
.PHONY: stress stressrace
stress: ## Run tests under stress.
$(info $(yellow)[WARNING] Use `dev test --stress $(subst ./,,$(PKG))$(if $(filter . -,$(TESTS)),, --filter $(TESTS))$(if $(TESTFLAGS), --test-args "$(TESTFLAGS)")$(if $(findstring 60m,$(TESTTIMEOUT)),, --timeout $(TESTTIMEOUT))` instead.$(term-reset))
$(xgo) test $(GOTESTFLAGS) $(GOFLAGS) $(GOMODVENDORFLAGS) -exec 'stress $(STRESSFLAGS)' -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' -run "$(TESTS)" -timeout 0 $(PKG) $(filter-out -v,$(TESTFLAGS)) -v -args -test.timeout $(TESTTIMEOUT)
COCKROACH_STRESS=true $(xgo) test $(GOTESTFLAGS) $(GOFLAGS) $(GOMODVENDORFLAGS) -exec 'stress $(STRESSFLAGS)' -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' -run "$(TESTS)" -timeout 0 $(PKG) $(filter-out -v,$(TESTFLAGS)) -v -args -test.timeout $(TESTTIMEOUT)
stressrace: ## Run tests under stress with the race detector enabled.
$(info $(yellow)[WARNING] Use `dev test --stress --race $(subst ./,,$(PKG))$(if $(filter . -,$(TESTS)),, --filter $(TESTS))$(if $(TESTFLAGS), --test-args "$(TESTFLAGS)")$(if $(findstring 60m,$(TESTTIMEOUT)),, --timeout $(TESTTIMEOUT))` instead.$(term-reset))
$(xgo) test $(GOTESTFLAGS) $(GOFLAGS) $(GOMODVENDORFLAGS) -exec 'stress $(STRESSFLAGS)' -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' -run "$(TESTS)" -timeout 0 $(PKG) $(filter-out -v,$(TESTFLAGS)) -v -args -test.timeout $(TESTTIMEOUT)
COCKROACH_STRESS=true $(xgo) test $(GOTESTFLAGS) $(GOFLAGS) $(GOMODVENDORFLAGS) -exec 'stress $(STRESSFLAGS)' -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' -run "$(TESTS)" -timeout 0 $(PKG) $(filter-out -v,$(TESTFLAGS)) -v -args -test.timeout $(TESTTIMEOUT)

.PHONY: roachprod-stress roachprod-stressrace
roachprod-stress roachprod-stressrace: bin/roachprod-stress
Expand Down
10 changes: 8 additions & 2 deletions build/teamcity/cockroach/ci/builds/build_impl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ fi

CONFIG="$1"

# Extra targets to build on Linux x86_64 only.
EXTRA_TARGETS=

# Extra targets to build on Linux x86_64 only.
if [ "$CONFIG" == "crosslinux" ]
then
DOC_TARGETS=$(grep '^//' docs/generated/bazel_targets.txt)
Expand All @@ -20,10 +21,15 @@ then
EXTRA_TARGETS="$DOC_TARGETS $GO_TARGETS $BINARY_TARGETS"
fi

# Extra targets to build on Unix only.
if [ "$CONFIG" != "crosswindows" ]
then
EXTRA_TARGETS="$EXTRA_TARGETS //pkg/cmd/roachprod"
fi

bazel build //pkg/cmd/bazci --config=ci
$(bazel info bazel-bin --config=ci)/pkg/cmd/bazci/bazci_/bazci --compilation_mode opt \
--config "$CONFIG" --config ci --config with_ui \
build //pkg/cmd/cockroach-short //pkg/cmd/cockroach \
//pkg/cmd/cockroach-sql \
//pkg/cmd/roachprod \
//pkg/cmd/cockroach-oss //c-deps:libgeos $EXTRA_TARGETS
12 changes: 11 additions & 1 deletion pkg/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,17 @@ func extraServerFlagInit(cmd *cobra.Command) error {
if serverSocketDir == "" {
serverCfg.SocketFile = ""
} else {
serverCfg.SocketFile = filepath.Join(serverSocketDir, ".s.PGSQL."+serverListenPort)
socketName := ".s.PGSQL." + serverListenPort
// On BSD, binding to a socket is limited to a path length of 104 characters
// (including the NUL terminator). In glibc, this limit is 108 characters.
// Otherwise, the bind operation fails with "invalid parameter".
if len(serverSocketDir) >= 104-1-len(socketName) {
return errors.WithHintf(
errors.Newf("value of --%s is too long: %s", cliflags.SocketDir.Name, serverSocketDir),
"The socket directory name must be shorter than %d characters.",
104-1-len(socketName))
}
serverCfg.SocketFile = filepath.Join(serverSocketDir, socketName)
}
}

Expand Down
65 changes: 65 additions & 0 deletions pkg/cli/interactive_tests/test_socket_name.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#! /usr/bin/env expect -f
#
source [file join [file dirname $argv0] common.tcl]

set longname "this-is-a-very-long-directory-name-the-point-is-to-be-more-than-one-hundred-and-twenty-three-characters/and-we-also-need-to-break-it-into-two-parts"

spawn /bin/bash
send "PS1=':''/# '\r"
eexpect ":/# "

send "mkdir -p $longname\r"
eexpect ":/# "

start_test "Check that the socket-dir flag checks the length of the directory."
send "$argv start-single-node --insecure --socket-dir=$longname\r"
eexpect "value of --socket-dir is too long"
eexpect "socket directory name must be shorter"
eexpect ":/# "
end_test

set crdb [file normalize $argv]
send "export BASEDIR=\$PWD\r"
eexpect ":/# "
send "export PREVTMP=\$TMPDIR\r"
eexpect ":/# "

start_test "Check that --background complains about the directory name if there is no default."
send "cd $longname\r"
eexpect ":/# "
send "export TMPDIR=\$PWD\r"
eexpect ":/# "
send "$crdb start-single-node --insecure --background\r"
eexpect "no suitable directory found for the --background notify socket"
eexpect "use a shorter directory name"
eexpect ":/# "
end_test

start_test "Check that --background can use --socket-name if specified and set to sane default."
send "$crdb start-single-node --insecure --background --socket-dir=\$BASEDIR --pid-file=\$BASEDIR/server_pid\r"
eexpect ":/# "
# check the server is running.
system "$crdb sql --insecure -e 'select 1'"
stop_server $crdb
end_test

start_test "Check that --background can use TMPDIR if specified and set to sane default."
# NB: we use a single-command override of TMPDIR (as opposed to using 'export') so that
# the following test below can reuse the value set above.
send "TMPDIR=\$PREVTMP $crdb start-single-node --insecure --background --pid-file=\$BASEDIR/server_pid\r"
eexpect ":/# "
# check the server is running.
system "$crdb sql --insecure -e 'select 1'"
stop_server $crdb
end_test

start_test "Check that --background can use cwd if TMPDIR is invalid."
# NB: at this point TMPDIR is still long, as per previous test.
send "cd \$BASEDIR\r"
eexpect ":/# "
send "$crdb start-single-node --insecure --background --pid-file=server_pid\r"
eexpect ":/# "
# check the server is running.
system "$crdb sql --insecure -e 'select 1'"
stop_server $crdb
end_test
18 changes: 13 additions & 5 deletions pkg/cli/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,10 @@ func waitForShutdown(
// INFO because a single interrupt is rather innocuous.
severity.INFO,
)
msgDouble := "Note: a second interrupt will skip graceful shutdown and terminate forcefully"
fmt.Fprintln(os.Stdout, msgDouble)
if !startCtx.inBackground {
msgDouble := "Note: a second interrupt will skip graceful shutdown and terminate forcefully"
fmt.Fprintln(os.Stdout, msgDouble)
}
}

// Start the draining process in a separate goroutine so that it
Expand Down Expand Up @@ -843,7 +845,9 @@ func waitForShutdown(

const msgDrain = "initiating graceful shutdown of server"
log.Ops.Info(shutdownCtx, msgDrain)
fmt.Fprintln(os.Stdout, msgDrain)
if !startCtx.inBackground {
fmt.Fprintln(os.Stdout, msgDrain)
}

// Notify the user every 5 second of the shutdown progress.
go func() {
Expand Down Expand Up @@ -895,12 +899,16 @@ func waitForShutdown(
case <-stopper.IsStopped():
const msgDone = "server drained and shutdown completed"
log.Ops.Infof(shutdownCtx, msgDone)
fmt.Fprintln(os.Stdout, msgDone)
if !startCtx.inBackground {
fmt.Fprintln(os.Stdout, msgDone)
}

case <-stopWithoutDrain:
const msgDone = "too early to drain; used hard shutdown instead"
log.Ops.Infof(shutdownCtx, msgDone)
fmt.Fprintln(os.Stdout, msgDone)
if !startCtx.inBackground {
fmt.Fprintln(os.Stdout, msgDone)
}
}
break
}
Expand Down
65 changes: 64 additions & 1 deletion pkg/cli/start_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (
"os/signal"
"strings"

"github.com/cockroachdb/cockroach/pkg/cli/cliflags"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/sdnotify"
"github.com/cockroachdb/cockroach/pkg/util/sysutil"
"github.com/cockroachdb/errors"
"golang.org/x/sys/unix"
)

Expand Down Expand Up @@ -67,8 +69,69 @@ func handleSignalDuringShutdown(sig os.Signal) {

const backgroundFlagDefined = true

// findGoodNotifyDir determines a good target directory
// to create the unix socket used to signal successful
// background startup (via sdnotify).
// A directory is "good" if it seems writable and its
// name is short enough.
func findGoodNotifyDir() (string, error) {
goodEnough := func(s string) bool {
if len(s) >= 104-1-len("sdnotify/notify.sock")-10 {
// On BSD, binding to a socket is limited to a path length of 104 characters
// (including the NUL terminator). In glibc, this limit is 108 characters.
// macOS also has a tendency to produce very long temporary directory names.
return false
}
st, err := os.Stat(s)
if err != nil {
return false
}
if !st.IsDir() || st.Mode()&0222 == 0 /* any write bits? */ {
// Note: we're confident the directory is unsuitable if none of the
// write bits are set, however there could be a false positive
// if some write bits are set.
//
// For example, if the process runs as a UID that does not match
// the directory owner UID or GID, and the write mode is 0220 or
// less, the sd socket creation will still fail.
// As such, the mode check here is merely a heuristic. We're
// OK with that: the actual write failure will produce a clear
// error message.
return false
}
return true
}

// Was --socket-dir configured? Try to use that.
if serverSocketDir != "" && goodEnough(serverSocketDir) {
return serverSocketDir, nil
}
// Do we have a temp directory? Try to use that.
if tmpDir := os.TempDir(); goodEnough(tmpDir) {
return tmpDir, nil
}
// Can we perhaps use the current directory?
if cwd, err := os.Getwd(); err == nil && goodEnough(cwd) {
return cwd, nil
}

// Note: we do not attempt to use the configured on-disk store
// directory(ies), because they may point to a filesystem that does
// not support unix sockets.

return "", errors.WithHintf(
errors.Newf("no suitable directory found for the --background notify socket"),
"Avoid using --%s altogether (preferred), or use a shorter directory name "+
"for --socket-dir, TMPDIR or the current directory.", cliflags.Background.Name)
}

func maybeRerunBackground() (bool, error) {
if startBackground {
notifyDir, err := findGoodNotifyDir()
if err != nil {
return true, err
}

args := make([]string, 0, len(os.Args))
foundBackground := false
for _, arg := range os.Args {
Expand All @@ -88,7 +151,7 @@ func maybeRerunBackground() (bool, error) {
// Notify to ourselves that we're restarting.
_ = os.Setenv(backgroundEnvVar, "1")

return true, sdnotify.Exec(cmd)
return true, sdnotify.Exec(cmd, notifyDir)
}
return false, nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/dev/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ func (d *dev) getStressArgs(stressCmdArg string, timeout time.Duration) []string
if stressCmdArg != "" {
stressCmdArgs = append(stressCmdArgs, stressCmdArg)
}
stressArgs = append(stressArgs, "--test_env=COCKROACH_STRESS=true")
stressArgs = append(stressArgs, "--run_under",
// NB: Run with -bazel, which propagates `TEST_TMPDIR` to `TMPDIR`,
// and -shardable-artifacts set such that we can merge the XML output
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/dev/testdata/datadriven/test
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bazel test pkg/util/tracing:all --nocache_test_results --test_env=GOTRACEBACK=al
exec
dev test --stress pkg/util/tracing --filter TestStartChild* --cpus=12 --timeout=25s
----
bazel test --local_cpu_resources=12 pkg/util/tracing:all --test_env=GOTRACEBACK=all --test_timeout=85 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' -maxtime=25s -p=12' '--test_filter=TestStartChild*' --test_sharding_strategy=disabled --test_output streamed
bazel test --local_cpu_resources=12 pkg/util/tracing:all --test_env=GOTRACEBACK=all --test_timeout=85 --test_env=COCKROACH_STRESS=true --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' -maxtime=25s -p=12' '--test_filter=TestStartChild*' --test_sharding_strategy=disabled --test_output streamed

exec
dev test //pkg/testutils --timeout=10s
Expand Down
10 changes: 5 additions & 5 deletions pkg/cmd/dev/testdata/datadriven/testlogic
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ bazel test --test_env=GOTRACEBACK=all --test_arg -test.count=5 --test_arg -show-
exec
dev testlogic base --files=auto_span_config_reconciliation --stress
----
bazel test --test_env=GOTRACEBACK=all --test_arg -show-sql --test_sharding_strategy=disabled --test_timeout=86400 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' ' //pkg/sql/logictest:logictest_test --test_filter 'TestLogic//^auto_span_config_reconciliation$/' --test_output streamed
bazel test --test_env=GOTRACEBACK=all --test_arg -show-sql --test_sharding_strategy=disabled --test_timeout=86400 --test_env=COCKROACH_STRESS=true --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' ' //pkg/sql/logictest:logictest_test --test_filter 'TestLogic//^auto_span_config_reconciliation$/' --test_output streamed

exec
dev testlogic base --files=auto_span_config_reconciliation --stress --timeout 1m --cpus 8
----
bazel test --test_env=GOTRACEBACK=all --local_cpu_resources=8 --test_arg -show-sql --test_sharding_strategy=disabled --test_timeout=120 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' -maxtime=1m0s -p=8' //pkg/sql/logictest:logictest_test --test_filter 'TestLogic//^auto_span_config_reconciliation$/' --test_output streamed
bazel test --test_env=GOTRACEBACK=all --local_cpu_resources=8 --test_arg -show-sql --test_sharding_strategy=disabled --test_timeout=120 --test_env=COCKROACH_STRESS=true --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' -maxtime=1m0s -p=8' //pkg/sql/logictest:logictest_test --test_filter 'TestLogic//^auto_span_config_reconciliation$/' --test_output streamed

exec
dev testlogic ccl --rewrite --show-logs -v --files distsql_automatic_stats --config 3node-tenant
Expand All @@ -66,14 +66,14 @@ bazel test --test_env=GOTRACEBACK=all --nocache_test_results --test_arg -test.v
exec
dev testlogic base --files=auto_span_config_reconciliation --stress --stream-output
----
bazel test --test_env=GOTRACEBACK=all --test_arg -show-sql --test_sharding_strategy=disabled --test_timeout=86400 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' ' //pkg/sql/logictest:logictest_test --test_filter 'TestLogic//^auto_span_config_reconciliation$/' --test_output streamed
bazel test --test_env=GOTRACEBACK=all --test_arg -show-sql --test_sharding_strategy=disabled --test_timeout=86400 --test_env=COCKROACH_STRESS=true --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' ' //pkg/sql/logictest:logictest_test --test_filter 'TestLogic//^auto_span_config_reconciliation$/' --test_output streamed

exec
dev testlogic base --files=auto_span_config_reconciliation --stress --stream-output
----
bazel test --test_env=GOTRACEBACK=all --test_arg -show-sql --test_sharding_strategy=disabled --test_timeout=86400 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' ' //pkg/sql/logictest:logictest_test --test_filter 'TestLogic//^auto_span_config_reconciliation$/' --test_output streamed
bazel test --test_env=GOTRACEBACK=all --test_arg -show-sql --test_sharding_strategy=disabled --test_timeout=86400 --test_env=COCKROACH_STRESS=true --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' ' //pkg/sql/logictest:logictest_test --test_filter 'TestLogic//^auto_span_config_reconciliation$/' --test_output streamed

exec
dev testlogic base --files=auto_span_config_reconciliation --stress --stream-output
----
bazel test --test_env=GOTRACEBACK=all --test_arg -show-sql --test_sharding_strategy=disabled --test_timeout=86400 --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' ' //pkg/sql/logictest:logictest_test --test_filter 'TestLogic//^auto_span_config_reconciliation$/' --test_output streamed
bazel test --test_env=GOTRACEBACK=all --test_arg -show-sql --test_sharding_strategy=disabled --test_timeout=86400 --test_env=COCKROACH_STRESS=true --run_under '@com_github_cockroachdb_stress//:stress -bazel -shardable-artifacts '"'"'XML_OUTPUT_FILE=dev merge-test-xmls'"'"' ' //pkg/sql/logictest:logictest_test --test_filter 'TestLogic//^auto_span_config_reconciliation$/' --test_output streamed
16 changes: 10 additions & 6 deletions pkg/sql/pgwire/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/cockroachdb/errors/stdstrings"
"github.com/cockroachdb/redact"
"github.com/lib/pq"
"github.com/stretchr/testify/require"
)

// TestAuthenticationAndHBARules exercises the authentication code
Expand Down Expand Up @@ -138,24 +139,27 @@ func makeSocketFile(t *testing.T) (socketDir, socketFile string, cleanupFn func(
// Unix sockets not supported on windows.
return "", "", func() {}
}
socketName := ".s.PGSQL." + socketConnVirtualPort
// We need a temp directory in which we'll create the unix socket.
//
// On BSD, binding to a socket is limited to a path length of 104 characters
// (including the NUL terminator). In glibc, this limit is 108 characters.
//
// macOS has a tendency to produce very long temporary directory names, so
// we are careful to keep all the constants involved short.
baseTmpDir := ""
if runtime.GOOS == "darwin" || strings.Contains(runtime.GOOS, "bsd") {
baseTmpDir := os.TempDir()
if len(baseTmpDir) >= 104-1-len(socketName)-1-len("TestAuth")-10 {
t.Logf("temp dir name too long: %s", baseTmpDir)
t.Logf("using /tmp instead.")
// Note: /tmp might fail in some systems, that's why we still prefer
// os.TempDir() if available.
baseTmpDir = "/tmp"
}
tempDir, err := ioutil.TempDir(baseTmpDir, "TestAuth")
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
// ".s.PGSQL.NNNN" is the standard unix socket name supported by pg clients.
return tempDir,
filepath.Join(tempDir, ".s.PGSQL."+socketConnVirtualPort),
filepath.Join(tempDir, socketName),
func() { _ = os.RemoveAll(tempDir) }
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/testutils/skip/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func UnderShort(t SkippableTest, args ...interface{}) {
// UnderStress skips this test when running under stress.
func UnderStress(t SkippableTest, args ...interface{}) {
t.Helper()
if NightlyStress() {
if Stress() {
t.Skip(append([]interface{}{"disabled under stress"}, args...))
}
}
Expand All @@ -123,7 +123,7 @@ func UnderStress(t SkippableTest, args ...interface{}) {
// run under stress with the -race flag.
func UnderStressRace(t SkippableTest, args ...interface{}) {
t.Helper()
if NightlyStress() && util.RaceEnabled {
if Stress() && util.RaceEnabled {
t.Skip(append([]interface{}{"disabled under stressrace"}, args...))
}
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/testutils/skip/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ package skip

import "github.com/cockroachdb/cockroach/pkg/util/envutil"

var stress = envutil.EnvOrDefaultBool("COCKROACH_NIGHTLY_STRESS", false)
var nightlyStress = envutil.EnvOrDefaultBool("COCKROACH_NIGHTLY_STRESS", false)

var stress = envutil.EnvOrDefaultBool("COCKROACH_STRESS", false)

// NightlyStress returns true iff the process is running as part of CockroachDB's
// nightly stress tests.
func NightlyStress() bool {
return stress
return nightlyStress
}

// Stress returns true iff the process is running under any instance of the stress
// harness, including the nightly one.
func Stress() bool {
return stress || nightlyStress
}
Loading

0 comments on commit 477644e

Please sign in to comment.