engine/test: Rework StorageEngine's test utils #1494

Merged
fyrchik merged 3 commits from a-savchuk/frostfs-node:prettify-engine-test-utils into master 2024-11-20 15:43:54 +00:00
Member

Close #1491

  • Remove testNewShard and setInitializedShards because they violated the default engine workflow. The correct workflow is: first use New(), followed by Open(), and then Init(). As a result, adding new logic to (*StorageEngine).Init caused several tests to fail with a panic when attempting to access uninitialized resources. Now, all engines created with the test utils must be
    initialized manually. The new helper method prepare can be used for that purpose.
  • Additionally, setInitializedShards hardcoded the shard worker pool size, which prevented it from being configured in tests and benchmarks. This has been fixed as well.
  • Ensure engine initialization is done wherever it was missing.
  • Refactor setShardsNumOpts, setShardsNumAdditionalOpts, and setShardsNum. Make them all depend on setShardsNumOpts.
Close #1491 - Remove `testNewShard` and `setInitializedShards` because they violated the default engine workflow. The correct workflow is: first use `New()`, followed by `Open()`, and then `Init()`. As a result, adding new logic to `(*StorageEngine).Init` caused several tests to fail with a panic when attempting to access uninitialized resources. Now, all engines created with the test utils must be initialized manually. The new helper method `prepare` can be used for that purpose. - Additionally, `setInitializedShards` hardcoded the shard worker pool size, which prevented it from being configured in tests and benchmarks. This has been fixed as well. - Ensure engine initialization is done wherever it was missing. - Refactor `setShardsNumOpts`, `setShardsNumAdditionalOpts`, and `setShardsNum`. Make them all depend on `setShardsNumOpts`.
a-savchuk added 3 commits 2024-11-13 11:09:00 +00:00
Use `setShardsNum` instead of `setInitializedShards` wherever possible.

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
Move `BenchmarkExists` from `engine_test.go` to `exists_test.go`
for better organization and clarity.

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
[#1491] engine/test: Rework engine test utils
All checks were successful
DCO action / DCO (pull_request) Successful in 1m47s
Tests and linters / Run gofumpt (pull_request) Successful in 2m12s
Vulncheck / Vulncheck (pull_request) Successful in 3m5s
Tests and linters / Staticcheck (pull_request) Successful in 3m40s
Build / Build Components (pull_request) Successful in 3m54s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m49s
Tests and linters / Lint (pull_request) Successful in 4m26s
Tests and linters / gopls check (pull_request) Successful in 4m42s
Tests and linters / Tests (pull_request) Successful in 6m32s
Tests and linters / Tests with -race (pull_request) Successful in 7m23s
b97db5f285
- Remove `testNewShard` and `setInitializedShards`. They violated
the default engine workflow, which should be: first use `New()`,
followed by `Open()`, and then `Init()`. As a result, adding new
logic to `(*StorageEngine).Init` caused several tests to fail with
a panic when attempting to access uninitialized resources. Now all
engines created with test utils must be initialized manually.
- Also, `setInitializedShards` hardcoded the shard worker pool size,
preventing it from being configured in tests/benchmarks Fix it too.
- Ensure engine initialization is done wherever it's missing.
- Refactor `setShardsNumOpts`, `setShardsNumAdditionalOpts`, and
`setShardsNum`. Make them all depend on `setShardsNumOpts`.

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
a-savchuk force-pushed prettify-engine-test-utils from b97db5f285 to bd772c4da3 2024-11-13 11:09:41 +00:00 Compare
fyrchik reviewed 2024-11-13 11:12:23 +00:00
@ -43,1 +42,3 @@
s2 := testNewShard(t)
te := testNewEngine(t).setShardsNum(t, 2)
e := te.engine
require.NoError(t, e.Open(context.Background()))
Owner

What about making init() method on the test engine?
The point of test helpers is to reduce boilerplate, it is much shorter to use testNewEngine(t).setShardsNum(t, 2).init() than te := testNewEngine(t).setShardsNum(t, 2) + 2 more lines.

What about making `init()` method on the test engine? The point of test helpers is to reduce boilerplate, it is much shorter to use `testNewEngine(t).setShardsNum(t, 2).init()` than `te := testNewEngine(t).setShardsNum(t, 2)` + 2 more lines.
a-savchuk force-pushed prettify-engine-test-utils from bd772c4da3 to 7fc6101bec 2024-11-13 11:50:41 +00:00 Compare
a-savchuk changed title from WIP: engine/test: Rework StorageEngine's test utils to engine/test: Rework StorageEngine's test utils 2024-11-13 12:13:11 +00:00
a-savchuk requested review from storage-core-developers 2024-11-13 12:13:20 +00:00
a-savchuk requested review from storage-core-committers 2024-11-13 12:13:21 +00:00
fyrchik approved these changes 2024-11-13 12:20:38 +00:00
dstepanov-yadro approved these changes 2024-11-13 13:21:31 +00:00
fyrchik merged commit 7fc6101bec into master 2024-11-13 13:48:30 +00:00
acid-ant approved these changes 2024-11-13 14:24:04 +00:00
a-savchuk deleted branch prettify-engine-test-utils 2024-11-13 15:39:26 +00:00
Sign in to join this conversation.
No reviewers
TrueCloudLab/storage-core-developers
No milestone
No project
No assignees
4 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#1494
No description provided.