| 160 | } |
| 161 | |
| 162 | func 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 | |
| 212 | func RunTest(t *testing.T, conf TestConfig) { |
| 213 | t.Helper() |