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

pull PushTrace up into main spec loop #40

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions scenario/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,32 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
}()
for idx, spec := range s.Tests {
sb := spec.Base()
wait := sb.Wait
if wait != nil && wait.Before != "" {
debug.Println(ctx, "wait: %s before", wait.Before)
time.Sleep(wait.BeforeDuration())
}
plugin := s.evalPlugins[idx]

rt := getRetry(ctx, scDefaults, plugin, spec)

// Create a brand new context that inherits the top-level context's
// cancel func. We want to set deadlines for each test spec and if
// we mutate the single supplied top-level context, then only the
// first deadline/timeout will be used.
specCtx, specCancel := context.WithCancel(ctx)

to := getTimeout(ctx, scDefaults, plugin, spec)
specTraceMsg := strconv.Itoa(idx)
if sb.Name != "" {
specTraceMsg += ":" + sb.Name
}
specCtx = gdtcontext.PushTrace(specCtx, specTraceMsg)
popTracer := func() {
specCtx = gdtcontext.PopTrace(specCtx)
}

wait := sb.Wait
if wait != nil && wait.Before != "" {
debug.Println(specCtx, "wait: %s before", wait.Before)
time.Sleep(wait.BeforeDuration())
}
plugin := s.evalPlugins[idx]

rt := getRetry(specCtx, scDefaults, plugin, spec)

to := getTimeout(specCtx, scDefaults, plugin, spec)
if to != nil {
specCtx, specCancel = context.WithTimeout(specCtx, to.Duration())
}
Expand All @@ -98,19 +108,21 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
select {
case <-specCtx.Done():
t.Fatalf("assertion failed: timeout exceeded (%s)", to.After)
popTracer()
specCancel()
break
case runres := <-ch:
res = runres.r
rterr = runres.err
}
if rterr != nil {
popTracer()
specCancel()
break
}

if wait != nil && wait.After != "" {
debug.Println(ctx, "wait: %s after", wait.After)
debug.Println(specCtx, "wait: %s after", wait.After)
time.Sleep(wait.AfterDuration())
}

Expand All @@ -123,6 +135,7 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
for _, fail := range res.Failures() {
t.Fatal(fail)
}
popTracer()
specCancel()
}
})
Expand All @@ -142,15 +155,6 @@ func (s *Scenario) runSpec(
idx int,
spec api.Evaluable,
) {
sb := spec.Base()
specTraceMsg := strconv.Itoa(idx)
if sb.Name != "" {
specTraceMsg += ":" + sb.Name
}
ctx = gdtcontext.PushTrace(ctx, specTraceMsg)
defer func() {
ctx = gdtcontext.PopTrace(ctx)
}()
if retry == nil || retry == api.NoRetry {
// Just evaluate the test spec once
res, err := spec.Eval(ctx)
Expand Down
2 changes: 1 addition & 1 deletion scenario/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestDebugFlushing(t *testing.T) {
w.Flush()
require.NotEqual(b.Len(), 0)
debugout := b.String()
require.Contains(debugout, "[gdt] [foo-debug-wait-flush] wait: 250ms before")
require.Contains(debugout, "[gdt] [foo-debug-wait-flush/0:bar] wait: 250ms before")
}

func TestNoRetry(t *testing.T) {
Expand Down
Loading