MCPcopy Index your code
hub / github.com/yuin/gopher-lua / TestContextTimeout

Function TestContextTimeout

state_test.go:401–422  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

399}
400
401func 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
424func TestContextCancel(t *testing.T) {
425 L := NewState()

Callers

nothing calls this directly

Calls 11

errorIfNotEqualFunction · 0.85
errorIfNilFunction · 0.85
errorIfFalseFunction · 0.85
errorIfNotNilFunction · 0.85
DoStringMethod · 0.80
NewStateFunction · 0.70
ErrorMethod · 0.65
CloseMethod · 0.45
SetContextMethod · 0.45
ContextMethod · 0.45
RemoveContextMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…