ozontech / allure-go

Complete Allure provider in Go which doesn't overload the interface usage
https://t.me/allure_go_chat
Apache License 2.0
306 stars 33 forks source link

Data race при использовании параллельных тестов #100

Open pstpn opened 1 day ago

pstpn commented 1 day ago

Описание бага Написал простой пример асинхронных тестов, запустил с флагом --race и наткнулся на гонки

Код

package service_test

import (
    "context"
    "testing"

    "github.com/ozontech/allure-go/pkg/framework/provider"
    "github.com/ozontech/allure-go/pkg/framework/suite"
)

type SetupSuite struct {
    suite.Suite
}

func (s *SetupSuite) Test_Auth_RegisterEmployee(t provider.T) {
    t.Title("[Auth] RegisterEmployee")
    t.Descriptionf("Register employee tests")
    t.Tags("auth")
    t.Parallel()

    t.WithNewAsyncStep("Incorrect company ID", func(sCtx provider.StepCtx) {
        ctx := context.TODO()
        sCtx.WithNewParameters("ctx", ctx)
    })
    t.WithNewAsyncStep("Correct request", func(sCtx provider.StepCtx) {
        ctx := context.TODO()
        sCtx.WithNewParameters("ctx", ctx)
    })

}

func TestRunner(t *testing.T) {
    suite.RunSuite(t, new(SetupSuite))
}

Запуск через консоль

go test ./internal/service/auth_test.go --race

Вывод

==================
WARNING: DATA RACE
Read at 0x00c0001b6d90 by goroutine 11:
  github.com/ozontech/allure-go/pkg/framework/core/allure_manager/ctx.(*testCtx).AddStep()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/allure_manager/ctx/test_ctx.go:19 +0x50
  github.com/ozontech/allure-go/pkg/framework/core/allure_manager/manager.(*allureManager).Step()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/allure_manager/manager/steps.go:9 +0x4c
  github.com/ozontech/allure-go/pkg/framework/core/common.(*Common).WithNewStep.deferwrap1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/common/steps.go:15 +0x54
  runtime.deferreturn()
      /opt/homebrew/opt/go/libexec/src/runtime/panic.go:605 +0x5c
  github.com/ozontech/allure-go/pkg/framework/core/common.(*Common).WithNewAsyncStep.func1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/common/steps.go:36 +0xc4

Previous write at 0x00c0001b6d90 by goroutine 12:
  github.com/ozontech/allure-go/pkg/framework/core/allure_manager/ctx.(*testCtx).AddStep()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/allure_manager/ctx/test_ctx.go:19 +0x108
  github.com/ozontech/allure-go/pkg/framework/core/allure_manager/manager.(*allureManager).Step()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/allure_manager/manager/steps.go:9 +0x4c
  github.com/ozontech/allure-go/pkg/framework/core/common.(*Common).WithNewStep.deferwrap1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/common/steps.go:15 +0x54
  runtime.deferreturn()
      /opt/homebrew/opt/go/libexec/src/runtime/panic.go:605 +0x5c
  github.com/ozontech/allure-go/pkg/framework/core/common.(*Common).WithNewAsyncStep.func1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/common/steps.go:36 +0xc4

Goroutine 11 (running) created at:
  github.com/ozontech/allure-go/pkg/framework/core/common.(*Common).WithNewAsyncStep()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/common/steps.go:34 +0x174
  command-line-arguments_test.(*SetupSuite).Test_Auth_RegisterEmployee()
      /Users/stepa/Study/Testing/internal/service/auth_test.go:21 +0x154
  runtime.call32()
      /opt/homebrew/opt/go/libexec/src/runtime/asm_arm64.s:505 +0x74
  reflect.Value.Call()
      /opt/homebrew/opt/go/libexec/src/reflect/value.go:365 +0x90
  github.com/ozontech/allure-go/pkg/framework/runner.(*testMethod).GetBody.func1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/runner/tests.go:155 +0x280
  github.com/ozontech/allure-go/pkg/framework/runner.(*runner).RunTests.func1.3.1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/runner/runner.go:206 +0x408
  testing.tRunner()
      /opt/homebrew/opt/go/libexec/src/testing/testing.go:1690 +0x184
  testing.(*T).Run.gowrap1()
      /opt/homebrew/opt/go/libexec/src/testing/testing.go:1743 +0x40

Goroutine 12 (finished) created at:
  github.com/ozontech/allure-go/pkg/framework/core/common.(*Common).WithNewAsyncStep()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/common/steps.go:34 +0x174
  command-line-arguments_test.(*SetupSuite).Test_Auth_RegisterEmployee()
      /Users/stepa/Study/Testing/internal/service/auth_test.go:25 +0x188
  runtime.call32()
      /opt/homebrew/opt/go/libexec/src/runtime/asm_arm64.s:505 +0x74
  reflect.Value.Call()
      /opt/homebrew/opt/go/libexec/src/reflect/value.go:365 +0x90
  github.com/ozontech/allure-go/pkg/framework/runner.(*testMethod).GetBody.func1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/runner/tests.go:155 +0x280
  github.com/ozontech/allure-go/pkg/framework/runner.(*runner).RunTests.func1.3.1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/runner/runner.go:206 +0x408
  testing.tRunner()
      /opt/homebrew/opt/go/libexec/src/testing/testing.go:1690 +0x184
  testing.(*T).Run.gowrap1()
      /opt/homebrew/opt/go/libexec/src/testing/testing.go:1743 +0x40
==================
==================
WARNING: DATA RACE
Read at 0x00c000054280 by goroutine 11:
  runtime.growslice()
      /opt/homebrew/opt/go/libexec/src/runtime/slice.go:177 +0x0
  github.com/ozontech/allure-go/pkg/framework/core/allure_manager/ctx.(*testCtx).AddStep()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/allure_manager/ctx/test_ctx.go:19 +0x88
  github.com/ozontech/allure-go/pkg/framework/core/allure_manager/manager.(*allureManager).Step()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/allure_manager/manager/steps.go:9 +0x4c
  github.com/ozontech/allure-go/pkg/framework/core/common.(*Common).WithNewStep.deferwrap1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/common/steps.go:15 +0x54
  runtime.deferreturn()
      /opt/homebrew/opt/go/libexec/src/runtime/panic.go:605 +0x5c
  github.com/ozontech/allure-go/pkg/framework/core/common.(*Common).WithNewAsyncStep.func1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/common/steps.go:36 +0xc4

Previous write at 0x00c000054280 by goroutine 12:
  github.com/ozontech/allure-go/pkg/framework/core/allure_manager/ctx.(*testCtx).AddStep()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/allure_manager/ctx/test_ctx.go:19 +0xac
  github.com/ozontech/allure-go/pkg/framework/core/allure_manager/manager.(*allureManager).Step()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/allure_manager/manager/steps.go:9 +0x4c
  github.com/ozontech/allure-go/pkg/framework/core/common.(*Common).WithNewStep.deferwrap1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/common/steps.go:15 +0x54
  runtime.deferreturn()
      /opt/homebrew/opt/go/libexec/src/runtime/panic.go:605 +0x5c
  github.com/ozontech/allure-go/pkg/framework/core/common.(*Common).WithNewAsyncStep.func1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/common/steps.go:36 +0xc4

Goroutine 11 (running) created at:
  github.com/ozontech/allure-go/pkg/framework/core/common.(*Common).WithNewAsyncStep()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/common/steps.go:34 +0x174
  command-line-arguments_test.(*SetupSuite).Test_Auth_RegisterEmployee()
      /Users/stepa/Study/Testing/internal/service/auth_test.go:21 +0x154
  runtime.call32()
      /opt/homebrew/opt/go/libexec/src/runtime/asm_arm64.s:505 +0x74
  reflect.Value.Call()
      /opt/homebrew/opt/go/libexec/src/reflect/value.go:365 +0x90
  github.com/ozontech/allure-go/pkg/framework/runner.(*testMethod).GetBody.func1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/runner/tests.go:155 +0x280
  github.com/ozontech/allure-go/pkg/framework/runner.(*runner).RunTests.func1.3.1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/runner/runner.go:206 +0x408
  testing.tRunner()
      /opt/homebrew/opt/go/libexec/src/testing/testing.go:1690 +0x184
  testing.(*T).Run.gowrap1()
      /opt/homebrew/opt/go/libexec/src/testing/testing.go:1743 +0x40

Goroutine 12 (finished) created at:
  github.com/ozontech/allure-go/pkg/framework/core/common.(*Common).WithNewAsyncStep()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/core/common/steps.go:34 +0x174
  command-line-arguments_test.(*SetupSuite).Test_Auth_RegisterEmployee()
      /Users/stepa/Study/Testing/internal/service/auth_test.go:25 +0x188
  runtime.call32()
      /opt/homebrew/opt/go/libexec/src/runtime/asm_arm64.s:505 +0x74
  reflect.Value.Call()
      /opt/homebrew/opt/go/libexec/src/reflect/value.go:365 +0x90
  github.com/ozontech/allure-go/pkg/framework/runner.(*testMethod).GetBody.func1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/runner/tests.go:155 +0x280
  github.com/ozontech/allure-go/pkg/framework/runner.(*runner).RunTests.func1.3.1()
      /Users/stepa/go/pkg/mod/github.com/ozontech/allure-go/pkg/framework@v0.6.32/runner/runner.go:206 +0x408
  testing.tRunner()
      /opt/homebrew/opt/go/libexec/src/testing/testing.go:1690 +0x184
  testing.(*T).Run.gowrap1()
      /opt/homebrew/opt/go/libexec/src/testing/testing.go:1743 +0x40
==================
--- FAIL: TestRunner (0.00s)
    --- FAIL: TestRunner/SetupSuite (0.00s)
        --- FAIL: TestRunner/SetupSuite/Tests (0.00s)
            --- FAIL: TestRunner/SetupSuite/Tests/Test_Auth_RegisterEmployee (0.00s)
                testing.go:1399: race detected during execution of test
FAIL
FAIL    command-line-arguments  0.353s
FAIL

Характеристики