Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock in async steps #45

Closed
xpoft opened this issue Nov 28, 2022 · 0 comments · Fixed by #46
Closed

Deadlock in async steps #45

xpoft opened this issue Nov 28, 2022 · 0 comments · Fixed by #46
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@xpoft
Copy link

xpoft commented Nov 28, 2022

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) {
			})
		})
	})
}
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
@koodeex koodeex added bug Something isn't working good first issue Good for newcomers labels Nov 28, 2022
@koodeex koodeex linked a pull request Nov 28, 2022 that will close this issue
@xpoft xpoft closed this as completed Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants