manager/state/raft/storage: fix TestCreateOpenInvalidDirFails#3087
Merged
thaJeztah merged 1 commit intoNov 19, 2022
Conversation
This was referenced Nov 19, 2022
Member
Author
|
@corhere @neersighted @dperny PTAL |
This test failed on macOS, but passed in CI:
--- FAIL: TestCreateOpenInvalidDirFails (0.00s)
walwrap_test.go:205:
Error Trace: walwrap_test.go:205
Error: An error is expected but got nil.
Test: TestCreateOpenInvalidDirFails
time="2022-11-19T14:36:00Z" level=info msg="repaired WAL error" error="unexpected EOF"
FAIL
It looks like this test was always broken; this test was added in
3e2cebe and running the test from
that commit and with the Go version used at the time showed the test
was failing;
git checkout 3e2cebe
docker run -it --rm -v $(pwd):/go/src/github.com/docker/swarmkit -w /go/src/github.com/docker/swarmkit golang:1.7 sh -c 'go test -v -run TestCreateOpenInvalidDirFails ./manager/state/raft/storage/'
=== RUN TestCreateOpenInvalidDirFails
--- FAIL: TestCreateOpenInvalidDirFails (0.01s)
Error Trace: walwrap_test.go:193
Error: An error is expected but got nil.
FAIL
exit status 1
FAIL github.com/docker/swarmkit/manager/state/raft/storage 0.031s
It took some digging to understand why, but when debugging the error
in CI (this part of the test _expected_ an error), it became apparent:
--- FAIL: TestCreateOpenInvalidDirFails (0.00s)
walwrap_test.go:207:
Error Trace: walwrap_test.go:207
Error: Received unexpected error:
mkdir /not: permission denied
Test: TestCreateOpenInvalidDirFails
time="2022-11-19T16:55:42Z" level=info msg="repaired WAL error" error="unexpected EOF"
So what happened was that;
- `walCryptor.Create()` is called, which calls `wal.Create()` (from
go.etcd.io/etcd/server/v3/wal/wal.go).
- `wal.Create()` creates a new `.tmp` directory at the same location as
the specified path (see https://github.com/etcd-io/etcd/blob/server/v3.5.1/server/wal/wal.go#L110-L127)
- in our case, the directory passed was `/not/existing/directory`, so
it tries to create `/not/existing/directory.tmp`.
- which fails, because CI doesn't run as `root` and doesn't have permissions
to create the path.
On macOS, running the test inside a container failed, as the tests are
run as `root` inside the container. Similarly, when updating the test
to use `t.TempDir()`, and using `/not/existing/directory` within that
directory, the test failed as well (as there's no permissions issue when
creating the `.tmp` directory inside the temp-dir).
So, in short, the test was broken from the start; calling `was.Create()`
using a non-existing directory is allowed, and not an error condition.
(If we _do_ want it to be an error-condition, we should implement code
to disallow this).
This patch removes the broken part from the test, and updates the
remaining part to use `t.TempDir()` and a directory inside that's
certain to be empty.
Also renaming the test to `TestOpenInvalidDirFails`, as the test now
only covers the `Open` case.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
35ab499 to
a78d56a
Compare
Codecov Report
@@ Coverage Diff @@
## master #3087 +/- ##
=========================================
Coverage ? 62.00%
=========================================
Files ? 156
Lines ? 24618
Branches ? 0
=========================================
Hits ? 15264
Misses ? 7763
Partials ? 1591 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
neersighted
approved these changes
Nov 19, 2022
Member
Author
|
Thx! Let me bring this one in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This test failed on macOS, but passed in CI:
It looks like this test was always broken; this test was added in 3e2cebe and running the test from that commit and with the Go version used at the time showed the test was failing;
It took some digging to understand why, but when debugging the error in CI (this part of the test expected an error), it became apparent:
So what happened was that;
walCryptor.Create()is called, which callswal.Create()(from go.etcd.io/etcd/server/v3/wal/wal.go).wal.Create()creates a new.tmpdirectory at the same location as the specified path (see https://github.com/etcd-io/etcd/blob/server/v3.5.1/server/wal/wal.go#L110-L127)/not/existing/directory, so it tries to create/not/existing/directory.tmp.rootand doesn't have permissions to create the path.On macOS, running the test inside a container failed, as the tests are run as
rootinside the container. Similarly, when updating the test to uset.TempDir(), and using/not/existing/directorywithin that directory, the test failed as well (as there's no permissions issue when creating the.tmpdirectory inside the temp-dir).So, in short, the test was broken from the start; calling
was.Create()using a non-existing directory is allowed, and not an error condition. (If we do want it to be an error-condition, we should implement code to disallow this).This patch removes the broken part from the test, and updates the remaining part to use
t.TempDir()and a directory inside that's certain to be empty.Also renaming the test to
TestOpenInvalidDirFails, as the test now only covers theOpencase.