Fix data race in unit tests #318

Merged
fyrchik merged 1 commit from dstepanov-yadro/frostfs-node:fix/processors_race into master 2023-05-04 14:06:31 +00:00
2 changed files with 5 additions and 4 deletions

View file

@ -2,7 +2,6 @@ package alphabet_test
import ( import (
"testing" "testing"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/alphabet" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/alphabet"
@ -140,7 +139,7 @@ func TestProcessorEmitsGasToNetmapIfNoParsedWallets(t *testing.T) {
processor.HandleGasEmission(timers.NewAlphabetEmitTick{}) processor.HandleGasEmission(timers.NewAlphabetEmitTick{})
time.Sleep(time.Second) processor.WaitPoolRunning()
require.EqualValues(t, []invokedMethod{ require.EqualValues(t, []invokedMethod{
{ {
@ -201,7 +200,7 @@ func TestProcessorDoesntEmitGasIfNoNetmapOrParsedWallets(t *testing.T) {
processor.HandleGasEmission(timers.NewAlphabetEmitTick{}) processor.HandleGasEmission(timers.NewAlphabetEmitTick{})
time.Sleep(time.Second) processor.WaitPoolRunning()
require.EqualValues(t, []invokedMethod{ require.EqualValues(t, []invokedMethod{
{ {

View file

@ -254,7 +254,9 @@ func TestHandleUnbind(t *testing.T) {
proc.handleBind(evBind) proc.handleBind(evBind)
time.Sleep(time.Second) for proc.pool.Running() > 0 {

How about require.Eventually? -- we can set maximum wait time there.

How about `require.Eventually`? -- we can set maximum wait time there.

A data race occurred due to a read before the pool goroutine was completed. I think it will end up being the same data race in case of eventually.

A data race occurred due to a read before the pool goroutine was completed. I think it will end up being the same data race in case of `eventually`.

Why, though? Eventually will fail the test if the condition is not true after some time, so the following code will not be executed.

Why, though? `Eventually` will fail the test if the condition is not true after some time, so the following code will not be executed.
time.Sleep(10 * time.Millisecond)
}
require.EqualValues(t, []frostfsid.CommonBindPrm{expBind}, id.remove, "invalid remove keys value") require.EqualValues(t, []frostfsid.CommonBindPrm{expBind}, id.remove, "invalid remove keys value")
require.EqualValues(t, []frostfsid.CommonBindPrm{expBind}, id.add, "invalid add keys value") require.EqualValues(t, []frostfsid.CommonBindPrm{expBind}, id.add, "invalid add keys value")