forked from TrueCloudLab/frostfs-node
[#1636] engine: Validate limiter release in unit tests
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
eb8b9b2b3b
commit
4685afb1dc
1 changed files with 26 additions and 0 deletions
|
@ -3,8 +3,10 @@ package engine
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"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"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree"
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree"
|
"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.WithPiloramaOptions(pilorama.WithPath(filepath.Join(t.TempDir(), "pilorama"))),
|
||||||
shard.WithMetaBaseOptions(testGetDefaultMetabaseOptions(t)...),
|
shard.WithMetaBaseOptions(testGetDefaultMetabaseOptions(t)...),
|
||||||
|
shard.WithLimiter(&testQoSLimiter{t: t}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,3 +154,26 @@ func newTestStorages(root string, smallSize uint64) ([]blobstor.SubStorage, *tes
|
||||||
},
|
},
|
||||||
}, smallFileStorage, largeFileStorage
|
}, 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
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue