(t *testing.T)
| 399 | } |
| 400 | |
| 401 | func TestContextTimeout(t *testing.T) { |
| 402 | L := NewState() |
| 403 | defer L.Close() |
| 404 | ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) |
| 405 | defer cancel() |
| 406 | L.SetContext(ctx) |
| 407 | errorIfNotEqual(t, ctx, L.Context()) |
| 408 | err := L.DoString(` |
| 409 | local clock = os.clock |
| 410 | function sleep(n) -- seconds |
| 411 | local t0 = clock() |
| 412 | while clock() - t0 <= n do end |
| 413 | end |
| 414 | sleep(3) |
| 415 | `) |
| 416 | errorIfNil(t, err) |
| 417 | errorIfFalse(t, strings.Contains(err.Error(), "context deadline exceeded"), "execution must be canceled") |
| 418 | |
| 419 | oldctx := L.RemoveContext() |
| 420 | errorIfNotEqual(t, ctx, oldctx) |
| 421 | errorIfNotNil(t, L.ctx) |
| 422 | } |
| 423 | |
| 424 | func TestContextCancel(t *testing.T) { |
| 425 | L := NewState() |
nothing calls this directly
no test coverage detected
searching dependent graphs…