Skip to content

Commit d96570d

Browse files
authored
Merge pull request #40 from jaypipes/panic-at-the-disco
pull PushTrace up into main spec loop
2 parents 6805ed0 + 380c50a commit d96570d

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

scenario/run.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,32 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
7070
}()
7171
for idx, spec := range s.Tests {
7272
sb := spec.Base()
73-
wait := sb.Wait
74-
if wait != nil && wait.Before != "" {
75-
debug.Println(ctx, "wait: %s before", wait.Before)
76-
time.Sleep(wait.BeforeDuration())
77-
}
78-
plugin := s.evalPlugins[idx]
79-
80-
rt := getRetry(ctx, scDefaults, plugin, spec)
8173

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

88-
to := getTimeout(ctx, scDefaults, plugin, spec)
80+
specTraceMsg := strconv.Itoa(idx)
81+
if sb.Name != "" {
82+
specTraceMsg += ":" + sb.Name
83+
}
84+
specCtx = gdtcontext.PushTrace(specCtx, specTraceMsg)
85+
popTracer := func() {
86+
specCtx = gdtcontext.PopTrace(specCtx)
87+
}
88+
89+
wait := sb.Wait
90+
if wait != nil && wait.Before != "" {
91+
debug.Println(specCtx, "wait: %s before", wait.Before)
92+
time.Sleep(wait.BeforeDuration())
93+
}
94+
plugin := s.evalPlugins[idx]
95+
96+
rt := getRetry(specCtx, scDefaults, plugin, spec)
97+
98+
to := getTimeout(specCtx, scDefaults, plugin, spec)
8999
if to != nil {
90100
specCtx, specCancel = context.WithTimeout(specCtx, to.Duration())
91101
}
@@ -98,19 +108,21 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
98108
select {
99109
case <-specCtx.Done():
100110
t.Fatalf("assertion failed: timeout exceeded (%s)", to.After)
111+
popTracer()
101112
specCancel()
102113
break
103114
case runres := <-ch:
104115
res = runres.r
105116
rterr = runres.err
106117
}
107118
if rterr != nil {
119+
popTracer()
108120
specCancel()
109121
break
110122
}
111123

112124
if wait != nil && wait.After != "" {
113-
debug.Println(ctx, "wait: %s after", wait.After)
125+
debug.Println(specCtx, "wait: %s after", wait.After)
114126
time.Sleep(wait.AfterDuration())
115127
}
116128

@@ -123,6 +135,7 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
123135
for _, fail := range res.Failures() {
124136
t.Fatal(fail)
125137
}
138+
popTracer()
126139
specCancel()
127140
}
128141
})
@@ -142,15 +155,6 @@ func (s *Scenario) runSpec(
142155
idx int,
143156
spec api.Evaluable,
144157
) {
145-
sb := spec.Base()
146-
specTraceMsg := strconv.Itoa(idx)
147-
if sb.Name != "" {
148-
specTraceMsg += ":" + sb.Name
149-
}
150-
ctx = gdtcontext.PushTrace(ctx, specTraceMsg)
151-
defer func() {
152-
ctx = gdtcontext.PopTrace(ctx)
153-
}()
154158
if retry == nil || retry == api.NoRetry {
155159
// Just evaluate the test spec once
156160
res, err := spec.Eval(ctx)

scenario/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func TestDebugFlushing(t *testing.T) {
113113
w.Flush()
114114
require.NotEqual(b.Len(), 0)
115115
debugout := b.String()
116-
require.Contains(debugout, "[gdt] [foo-debug-wait-flush] wait: 250ms before")
116+
require.Contains(debugout, "[gdt] [foo-debug-wait-flush/0:bar] wait: 250ms before")
117117
}
118118

119119
func TestNoRetry(t *testing.T) {

0 commit comments

Comments
 (0)