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
317 stars 34 forks source link

Deadlock in async steps #45

Closed xpoft closed 1 year ago

xpoft commented 1 year ago

Describe the bug

  1. WithNewAsyncStep in WithNewAsyncStep will cause deadlock and tests will never finish.

  2. WithNewAsyncStep in step won't be executed async

To Reproduce

  1. example
    
    package my_suite

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

func (s *Suite) TestSome3(t provider.T) { t.Parallel()

t.WithNewStep("sync-step1", func(sCtx provider.StepCtx) {
    sCtx.WithNewAsyncStep("sync-step1-async-step-1", func(sCtx provider.StepCtx) {
        sCtx.WithNewAsyncStep("sync-step1-async-step-1-step1", func(sCtx provider.StepCtx) {
        })
    })
})

}


2.

package my_suite

import ( "time"

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

)

func (s *Suite) TestSome3(t provider.T) { t.Parallel()

startedAt := time.Now()
timeSinceStart := func() int64 {
    return int64(time.Since(startedAt).Round(time.Second).Seconds())
}
sleepDuration := 5 * time.Second

t.WithNewStep("sync-step1", func(sCtx provider.StepCtx) {
    sCtx.Logf("sync-step1. start: %d", timeSinceStart())
    time.Sleep(sleepDuration)
    sCtx.Logf("sync-step1. finish: %d", timeSinceStart())

    sCtx.WithNewAsyncStep("sync-step1-async-step-1", func(sCtx provider.StepCtx) {
        sCtx.Logf("sync-step1-async-step-1. start: %d", timeSinceStart())
        time.Sleep(sleepDuration)
        sCtx.Logf("sync-step1-async-step-1. finish: %d", timeSinceStart())
    })
    sCtx.WithNewAsyncStep("sync-step1-async-step-2", func(sCtx provider.StepCtx) {
        sCtx.Logf("sync-step1-async-step-2. start: %d", timeSinceStart())
        time.Sleep(sleepDuration)
        sCtx.Logf("sync-step1-async-step-2. finish: %d", timeSinceStart())
    })
})

t.WithNewStep("sync-step2", func(sCtx provider.StepCtx) {
    sCtx.Logf("sync-step2. start: %d", timeSinceStart())
    time.Sleep(sleepDuration)
    sCtx.Logf("sync-step2. finish: %d", timeSinceStart())
})

}


output
step_context.go:104: sync-step1. finish: 5
step_context.go:104: sync-step1-async-step-1. start: 5
step_context.go:104: sync-step1-async-step-1. finish: 10
step_context.go:104: sync-step1-async-step-2. start: 10
step_context.go:104: sync-step1-async-step-2. finish: 15
step_context.go:104: sync-step2. start: 15
step_context.go:104: sync-step2. finish: 20


**Expected behavior**
1. No deadlock
2. Async steps