[#1636] engine: Validate limiter release in unit tests
All checks were successful
DCO action / DCO (pull_request) Successful in 33s
Vulncheck / Vulncheck (pull_request) Successful in 1m2s
Build / Build Components (pull_request) Successful in 1m24s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m26s
Tests and linters / Run gofumpt (pull_request) Successful in 2m53s
Tests and linters / Lint (pull_request) Successful in 3m4s
Tests and linters / Staticcheck (pull_request) Successful in 3m9s
Tests and linters / Tests (pull_request) Successful in 3m11s
Tests and linters / gopls check (pull_request) Successful in 3m43s
Tests and linters / Tests with -race (pull_request) Successful in 3m53s
Tests and linters / Run gofumpt (push) Successful in 34s
Vulncheck / Vulncheck (push) Successful in 1m7s
Pre-commit hooks / Pre-commit (push) Successful in 1m56s
Build / Build Components (push) Successful in 2m9s
Tests and linters / Staticcheck (push) Successful in 2m39s
Tests and linters / gopls check (push) Successful in 2m51s
Tests and linters / Tests (push) Successful in 3m17s
Tests and linters / Lint (push) Successful in 3m41s
Tests and linters / Tests with -race (push) Successful in 4m33s
OCI image / Build container images (push) Successful in 4m30s

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2025-02-28 10:21:30 +03:00
parent eb8b9b2b3b
commit 4685afb1dc
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0

View file

@ -3,8 +3,10 @@ package engine
import (
"context"
"path/filepath"
"sync/atomic"
"testing"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/qos"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
@ -90,6 +92,7 @@ func testGetDefaultShardOptions(t testing.TB) []shard.Option {
),
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(t.TempDir(), "pilorama"))),
shard.WithMetaBaseOptions(testGetDefaultMetabaseOptions(t)...),
shard.WithLimiter(&testQoSLimiter{t: t}),
}
}
@ -151,3 +154,26 @@ func newTestStorages(root string, smallSize uint64) ([]blobstor.SubStorage, *tes
},
}, smallFileStorage, largeFileStorage
}
var _ qos.Limiter = (*testQoSLimiter)(nil)
type testQoSLimiter struct {
t testing.TB
read atomic.Int64
write atomic.Int64
}
func (t *testQoSLimiter) Close() {
require.Equal(t.t, int64(0), t.read.Load(), "read requests count after limiter close must be 0")
require.Equal(t.t, int64(0), t.write.Load(), "write requests count after limiter close must be 0")
}
func (t *testQoSLimiter) ReadRequest(context.Context) (qos.ReleaseFunc, error) {
t.read.Add(1)
return func() { t.read.Add(-1) }, nil
}
func (t *testQoSLimiter) WriteRequest(context.Context) (qos.ReleaseFunc, error) {
t.write.Add(1)
return func() { t.write.Add(-1) }, nil
}