diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index cb27914ae0..1b0bd67f12 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -187,8 +187,8 @@ func notify(ctx context.Context, input *notifyInput) error { return handleWorkflows(ctx, detectedWorkflows, commit, input, ref.String()) } -func getGitRepoAndCommit(_ context.Context, input *notifyInput) (*git.Repository, *git.Commit, git.RefName, error) { - gitRepo, err := gitrepo.OpenRepository(context.Background(), input.Repo) +func getGitRepoAndCommit(ctx context.Context, input *notifyInput) (*git.Repository, *git.Commit, git.RefName, error) { + gitRepo, err := gitrepo.OpenRepository(ctx, input.Repo) if err != nil { return nil, nil, "", fmt.Errorf("git.OpenRepository: %w", err) } @@ -598,7 +598,7 @@ func DetectAndHandleSchedules(ctx context.Context, repo *repo_model.Repository) return nil } - gitRepo, err := gitrepo.OpenRepository(context.Background(), repo) + gitRepo, err := gitrepo.OpenRepository(ctx, repo) if err != nil { return fmt.Errorf("git.OpenRepository: %w", err) } diff --git a/tests/test_utils.go b/tests/test_utils.go index 6432dfc271..0fc9329b77 100644 --- a/tests/test_utils.go +++ b/tests/test_utils.go @@ -263,6 +263,11 @@ func cancelProcesses(t testing.TB, delay time.Duration) { for _, p := range processes { t.Logf("PrepareTestEnv:Remaining Process: %q", p.Description) } + stacks := allGoroutineStacks() + t.Errorf("All goroutine stacks during process cancellation failure:\n%s", string(stacks)) + // exit so that we don't spin in a loop executing `delay` wait over and over again when we won't be able to + // complete tests correctly due to the environmental issue present. + exitf("terminating test run due to unrecoverable failure") return } runtime.Gosched() // let the context cancellation propagate @@ -271,6 +276,18 @@ func cancelProcesses(t testing.TB, delay time.Duration) { t.Logf("PrepareTestEnv: all processes cancelled within %s", time.Since(start)) } +// allGoroutineStacks is the same as runtime/debug.Stack(), but it captures the stack of all goroutines. +func allGoroutineStacks() []byte { + buf := make([]byte, 1024) + for { + n := runtime.Stack(buf, true) + if n < len(buf) { + return buf[:n] + } + buf = make([]byte, 2*len(buf)) + } +} + func PrepareGitRepoDirectory(t testing.TB) { setting.RepoRootPath = t.TempDir() require.NoError(t, unittest.CopyDir(preparedDir, setting.RepoRootPath))