(t *testing.T)
| 422 | } |
| 423 | |
| 424 | func TestContextCancel(t *testing.T) { |
| 425 | L := NewState() |
| 426 | defer L.Close() |
| 427 | ctx, cancel := context.WithCancel(context.Background()) |
| 428 | errch := make(chan error, 1) |
| 429 | L.SetContext(ctx) |
| 430 | go func() { |
| 431 | errch <- L.DoString(` |
| 432 | local clock = os.clock |
| 433 | function sleep(n) -- seconds |
| 434 | local t0 = clock() |
| 435 | while clock() - t0 <= n do end |
| 436 | end |
| 437 | sleep(3) |
| 438 | `) |
| 439 | }() |
| 440 | time.Sleep(1 * time.Second) |
| 441 | cancel() |
| 442 | err := <-errch |
| 443 | errorIfNil(t, err) |
| 444 | errorIfFalse(t, strings.Contains(err.Error(), "context canceled"), "execution must be canceled") |
| 445 | } |
| 446 | |
| 447 | func TestContextWithCroutine(t *testing.T) { |
| 448 | L := NewState() |
nothing calls this directly
no test coverage detected
searching dependent graphs…