[#139] test: Add test storage implementation #173
No reviewers
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/frostfs-node#173
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "ale64bit/frostfs-node:fix/139-unit_test_storage"
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?
This aims to reduce the usage of chmod hackery to induce or simulate
OS-related failures.
Signed-off-by: Alejandro Lopez a.lopez@yadro.com
f6b6097f0c
to4907d78dab
It seems that it was easier to use gomockery :-)
I agree :))
4907d78dab
toe5c5235357
(force push only for fixing
go.mod
,go.sum
conflicts)@ -30,3 +30,3 @@
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.2
Can we have a separate commit for this?
done
We still have some changes in
go.sum
hm, I ran
go mod tidy
. I don't really touch these files manually. Maybe it's ok now.@ -16,3 +16,1 @@
const blobovniczaDir = "blobovniczas"
func defaultStorages(p string, smallSizeLimit uint64) []SubStorage {
func defaultTestStorages(p string, smallSizeLimit uint64) ([]SubStorage, *teststore.TestStore, *teststore.TestStore) {
Do we need to return the last 2 arguments? Why not casting a type from
SubStorage
?What's wrong with returning both arguments? Seems to me that way it's more clear what is returned and the cast/indexing is unnecessary (those assume a type and slice size).
That the number of returned arguments directly depends on the slice length, and casting is not that hard.
I don't insist, just share an opinion.
Seems to me it's more clear to return struct with named fields. Casting is evil and should be prohibited.
@ -0,0 +55,4 @@
switch {
case s.overrides.Open != nil:
return s.overrides.Open(readOnly)
case s.st != nil:
Сan we enforce this in
new
and make this branch adefault
? Implicit panic is also not bad here.This is intentional, so that a
TreeStore
can also be used purely as a mock (e.g. to verify only certain calls are executed and nothing is propagated to any underlying storage).Re. the implicit panic, isn't better an explicit panic with specific error message rather than a nil dereference panic which might not be immediately clear?
@ -43,0 +53,4 @@
var allowedMode atomic.Int64
openFileMetabase := func(p string, f int, perm fs.FileMode) (*os.File, error) {
if int64(f&3) == allowedMode.Load() {
3
looks like a magic here, can we define a constant asos.O_RDONLY | os.O_RDWR | os.O_WRONLY
? Or somehow refer to them in the comment for the named constant.done
@ -43,0 +56,4 @@
if int64(f&3) == allowedMode.Load() {
return os.OpenFile(p, f, perm)
}
return nil, teststore.ErrDiskExploded
Maybe
syscall.EPERM
orfs.ErrPermission
?done. Is there any value in returning an error that is guaranteed to not be specially handled or better to use a relevant error for this path?
@ -209,3 +210,3 @@
_, err = os.Stat(p) // sanity check
require.NoError(t, err)
require.NoError(t, os.Chmod(p, 0))
require.NoError(t, os.Truncate(p, 0))
What do we achieve with
Truncate
here?os.Chmod
was used here to cause the file to not be read properly, but the same can be achieved withos.Truncate
so that it can't be unmarshalled. I thought at leastos.Truncate
didn't depend on the user running the test.I mean the purpose is not obvious to me, as a code reader. May be just write
"corrupted data"
in the file?ah I see. Yes, good point. I added a comment about it on this line.
e5c5235357
todd99c28fae
dd99c28fae
to6df9f44cfd