[#139] test: Add test storage implementation #173

Merged
fyrchik merged 1 commit from ale64bit/frostfs-node:fix/139-unit_test_storage into master 2023-03-29 14:28:50 +00:00
Member

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

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>
ale64bit force-pushed fix/139-unit_test_storage from f6b6097f0c to 4907d78dab 2023-03-24 09:31:15 +00:00 Compare
ale64bit requested review from storage-core-committers 2023-03-24 09:31:44 +00:00
ale64bit requested review from storage-core-developers 2023-03-24 09:31:44 +00:00
dstepanov-yadro approved these changes 2023-03-28 06:26:45 +00:00

It seems that it was easier to use gomockery :-)

It seems that it was easier to use gomockery :-)
Author
Member

It seems that it was easier to use gomockery :-)

I agree :))

> It seems that it was easier to use gomockery :-) I agree :))
ale64bit force-pushed fix/139-unit_test_storage from 4907d78dab to e5c5235357 2023-03-29 07:25:16 +00:00 Compare
Author
Member

(force push only for fixing go.mod, go.sum conflicts)

(force push only for fixing `go.mod`, `go.sum` conflicts)
ale64bit requested review from dstepanov-yadro 2023-03-29 07:26:19 +00:00
dstepanov-yadro approved these changes 2023-03-29 07:51:44 +00:00
fyrchik reviewed 2023-03-29 11:28:01 +00:00
go.mod Outdated
@ -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
Owner

Can we have a separate commit for this?

Can we have a separate commit for this?
Author
Member

done

done
Owner

We still have some changes in go.sum

We still have some changes in `go.sum`
Author
Member

hm, I ran go mod tidy. I don't really touch these files manually. Maybe it's ok now.

hm, I ran `go mod tidy`. I don't really touch these files manually. Maybe it's ok now.
fyrchik marked this conversation as resolved
@ -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) {
Owner

Do we need to return the last 2 arguments? Why not casting a type from SubStorage?

Do we need to return the last 2 arguments? Why not casting a type from `SubStorage`?
Author
Member

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).

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).
Owner

That the number of returned arguments directly depends on the slice length, and casting is not that hard.

That the number of returned arguments directly depends on the slice length, and casting is not that hard.
Owner

I don't insist, just share an opinion.

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.

Seems to me it's more clear to return struct with named fields. Casting is evil and should be prohibited.
fyrchik marked this conversation as resolved
@ -0,0 +55,4 @@
switch {
case s.overrides.Open != nil:
return s.overrides.Open(readOnly)
case s.st != nil:
Owner

Сan we enforce this in new and make this branch a default? Implicit panic is also not bad here.

Сan we enforce this in `new` and make this branch a `default`? Implicit panic is also not bad here.
Author
Member

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?

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?
fyrchik marked this conversation as resolved
@ -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() {
Owner

3 looks like a magic here, can we define a constant as os.O_RDONLY | os.O_RDWR | os.O_WRONLY? Or somehow refer to them in the comment for the named constant.

`3` looks like a magic here, can we define a constant as `os.O_RDONLY | os.O_RDWR | os.O_WRONLY`? Or somehow refer to them in the comment for the named constant.
Author
Member

done

done
fyrchik marked this conversation as resolved
@ -43,0 +56,4 @@
if int64(f&3) == allowedMode.Load() {
return os.OpenFile(p, f, perm)
}
return nil, teststore.ErrDiskExploded
Owner

Maybe syscall.EPERM or fs.ErrPermission?

Maybe `syscall.EPERM` or `fs.ErrPermission`?
Author
Member

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?

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?
fyrchik marked this conversation as resolved
@ -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))
Owner

What do we achieve with Truncate here?

What do we achieve with `Truncate` here?
Author
Member

os.Chmod was used here to cause the file to not be read properly, but the same can be achieved with os.Truncate so that it can't be unmarshalled. I thought at least os.Truncate didn't depend on the user running the test.

`os.Chmod` was used here to cause the file to not be read properly, but the same can be achieved with `os.Truncate` so that it can't be unmarshalled. I thought at least `os.Truncate` didn't depend on the user running the test.
Owner

I mean the purpose is not obvious to me, as a code reader. May be just write "corrupted data" in the file?

I mean the purpose is not obvious to me, as a code reader. May be just write `"corrupted data"` in the file?
Author
Member

ah I see. Yes, good point. I added a comment about it on this line.

ah I see. Yes, good point. I added a comment about it on this line.
fyrchik marked this conversation as resolved
ale64bit force-pushed fix/139-unit_test_storage from e5c5235357 to dd99c28fae 2023-03-29 11:49:32 +00:00 Compare
ale64bit force-pushed fix/139-unit_test_storage from dd99c28fae to 6df9f44cfd 2023-03-29 14:25:48 +00:00 Compare
ale64bit requested review from dstepanov-yadro 2023-03-29 14:27:07 +00:00
fyrchik approved these changes 2023-03-29 14:28:38 +00:00
fyrchik merged commit 341fe1688f into master 2023-03-29 14:28:50 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-node#173
No description provided.