MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / runTestFromContext

Function runTestFromContext

pkg/util/test/test.go:162–210  ·  view source on GitHub ↗
(ctx context.Context, conf TestConfig)

Source from the content-addressed store, hash-verified

160}
161
162func runTestFromContext(ctx context.Context, conf TestConfig) {
163 t := MustTFromContext(ctx)
164 t.Helper()
165
166 if conf.Parallel {
167 t.Parallel()
168 }
169 a, ctx := New(t)
170 ctx, cancel := context.WithDeadline(ctx, func() time.Time {
171 timeout := conf.Timeout
172 if timeout == 0 {
173 timeout = defaultTestTimeout
174 }
175 dl := time.Now().Add(timeout)
176 tDL, ok := t.Deadline()
177 if ok && tDL.Before(dl) {
178 return tDL
179 }
180 return dl
181 }())
182 defer cancel()
183
184 dl, ok := ctx.Deadline()
185 if !ok {
186 panic("missing deadline in context")
187 }
188 timeout := time.Until(dl)
189
190 start := time.Now()
191 doneCh := make(chan struct{})
192 defer func() {
193 t.Helper()
194 close(doneCh)
195 if d := time.Since(start); d > timeout {
196 t.Errorf("%s took too long to execute. Expected execution time below %v, ran for %v", t.Name(), timeout, d)
197 }
198 }()
199 go func() {
200 for {
201 select {
202 case <-doneCh:
203 return
204 case <-time.Tick(timeout / 4):
205 t.Logf("%s is taking a long time to execute. Expected execution time below %v, running already for: %v", t.Name(), timeout, time.Since(start))
206 }
207 }
208 }()
209 conf.Func(ctx, a)
210}
211
212func RunTest(t *testing.T, conf TestConfig) {
213 t.Helper()

Callers 2

RunTestFunction · 0.85
RunSubtestFromContextFunction · 0.85

Calls 7

MustTFromContextFunction · 0.85
DeadlineMethod · 0.80
NewFunction · 0.70
AddMethod · 0.65
NowMethod · 0.65
ErrorfMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected