From 3b589fb3b2a2c3a3e34a998e8806d1e8641c61f0 Mon Sep 17 00:00:00 2001 From: Piotr Tabor Date: Sat, 2 Apr 2022 15:22:41 +0200 Subject: [PATCH] Fix TestauthTokenBundleOnOverwrite on OsX: ``` % (cd client/v3 && env go test -short -timeout=3m --race ./...) --- FAIL: TestAuthTokenBundleNoOverwrite (0.00s) client_test.go:210: listen unix /var/folders/t1/3m8z9xz93t9c3vpt7zyzjm6w00374n/T/TestAuthTokenBundleNoOverwrite3197524989/001/etcd-auth-test:0: bind: invalid argument FAIL FAIL go.etcd.io/etcd/client/v3 4.270s ``` The reason was that the path exceeded 108 chars (that is too much for socket). In the mitigation we first change chroot (working directory) to the tempDir... such the path is 'local'. --- client/pkg/testutil/before.go | 40 ++++++++++++++++++++++++++++++++++ client/v3/client_test.go | 8 +++++-- tests/framework/e2e/testing.go | 14 +----------- 3 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 client/pkg/testutil/before.go diff --git a/client/pkg/testutil/before.go b/client/pkg/testutil/before.go new file mode 100644 index 000000000..801aa042d --- /dev/null +++ b/client/pkg/testutil/before.go @@ -0,0 +1,40 @@ +// Copyright 2022 The etcd Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package testutil + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +// These are constants from "go.etcd.io/etcd/server/v3/verify", +// but we don't want to take dependency. +const ENV_VERIFY = "ETCD_VERIFY" +const ENV_VERIFY_ALL_VALUE = "all" + +func BeforeTest(t testing.TB) { + RegisterLeakDetection(t) + os.Setenv(ENV_VERIFY, ENV_VERIFY_ALL_VALUE) + + path, err := os.Getwd() + assert.NoError(t, err) + tempDir := t.TempDir() + assert.NoError(t, os.Chdir(tempDir)) + t.Logf("Changing working directory to: %s", tempDir) + + t.Cleanup(func() { assert.NoError(t, os.Chdir(path)) }) +} diff --git a/client/v3/client_test.go b/client/v3/client_test.go index b8c62a95b..4884fe646 100644 --- a/client/v3/client_test.go +++ b/client/v3/client_test.go @@ -18,7 +18,6 @@ import ( "context" "fmt" "net" - "path/filepath" "testing" "time" @@ -204,8 +203,13 @@ func TestZapWithLogger(t *testing.T) { } func TestAuthTokenBundleNoOverwrite(t *testing.T) { + // This call in particular changes working directory to the tmp dir of + // the test. The `etcd-auth-test:0` can be created in local directory, + // not exceeding the longest allowed path on OsX. + testutil.BeforeTest(t) + // Create a mock AuthServer to handle Authenticate RPCs. - lis, err := net.Listen("unix", filepath.Join(t.TempDir(), "etcd-auth-test:0")) + lis, err := net.Listen("unix", "etcd-auth-test:0") if err != nil { t.Fatal(err) } diff --git a/tests/framework/e2e/testing.go b/tests/framework/e2e/testing.go index e1447146c..7d7de27fd 100644 --- a/tests/framework/e2e/testing.go +++ b/tests/framework/e2e/testing.go @@ -15,24 +15,12 @@ package e2e import ( - "os" "testing" - "github.com/stretchr/testify/assert" "go.etcd.io/etcd/client/pkg/v3/testutil" - "go.etcd.io/etcd/server/v3/verify" ) func BeforeTest(t testing.TB) { SkipInShortMode(t) - testutil.RegisterLeakDetection(t) - os.Setenv(verify.ENV_VERIFY, verify.ENV_VERIFY_ALL_VALUE) - - path, err := os.Getwd() - assert.NoError(t, err) - tempDir := t.TempDir() - assert.NoError(t, os.Chdir(tempDir)) - t.Logf("Changing working directory to: %s", tempDir) - - t.Cleanup(func() { assert.NoError(t, os.Chdir(path)) }) + testutil.BeforeTest(t) }