Unit tests fail in docker container under root user #139
Labels
No labels
P0
P1
P2
P3
badger
frostfs-adm
frostfs-cli
frostfs-ir
frostfs-lens
frostfs-node
good first issue
triage
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-node#139
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Current Behavior
I run unit test inside docker container and fail, while same tests pass well in normal Linux host environment.
As a consequence, unit tests fail in CI.
Steps to Reproduce
Here is a test run log.
There is a bunch of tests where we try to emulate some problems with the storage. This is done by setting bad permissions on some internal directories.
Tests from docker are run from root, so changing permissions doesn't work.
I have tried adding a user and running tests from it -- everything works.
I see 2 solutions here:
Is it possible to use https://pkg.go.dev/io/fs#FS instead of
os
everywhere? This way we can mock these things without resorting to perm tricks and make at least the unit tests fully hermetic.Using
fs.FS
is not trivial for the following reasons:OpenFile
function, but this is not quite enough since it still requires anos.File
in the return type and internally it uses several OS-specific operations.We are evaluating what can be done.
Unit tests fail in docker containerto Unit tests fail in docker container under root userLet's add some artificial unit test to show a warning when tests are running under
root
, at least for debugging purposes for now, since our code is quite entangled withos
usage and bbolt itself.My suggestion:
integration
tag.make test
to run unit tests withintegration
tag (unit tests with tag and without any tag will be run)make ci-test
, which will run unit tests withoutintegration
tag and be used in CI/CD pipeline.IMHO, any unit test that requires OS interaction is not really "unit" anymore. The thing with those failing tests is that they use some unorthodox way of verifying their behavior, so we should probably fix that if possible.
But the tag could be useful for e2e tests, etc. as you mention. I'll let others chime in.
There are 2 groups of tests here:
logical
) increase engine error counter.For most of this cases we could actually use a test interface (memory store).
I suggest making a list of currently failing tests, and change them one-by-one.
What about we create a
TestStorage
implementation ofcommon.Storage
which can wrap other implementations and passthrough certain calls to the underlying storage while setting some test expectations or mocking calls for others? That way, we can express exactly the expected behavior of each substorage while minimizing the amount of OS interaction.e.g.
Not necessarily like above, but hopefully you get the idea.
Related: #149
Let me know if the changes in #160 look reasonable. I'm not a big fan of mocking in general, but in measure I guess it's better than chmodding stuff or depending on particular conditions (such as the user running the test) for results.
There are two tests which still fail under root: