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

Function TestContextWithCroutine

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

Source from the content-addressed store, hash-verified

445}
446
447func TestContextWithCroutine(t *testing.T) {
448 L := NewState()
449 defer L.Close()
450 ctx, cancel := context.WithCancel(context.Background())
451 L.SetContext(ctx)
452 defer cancel()
453 L.DoString(`
454 function coro()
455 local i = 0
456 while true do
457 coroutine.yield(i)
458 i = i+1
459 end
460 return i
461 end
462 `)
463 co, cocancel := L.NewThread()
464 defer cocancel()
465 fn := L.GetGlobal("coro").(*LFunction)
466 _, err, values := L.Resume(co, fn)
467 errorIfNotNil(t, err)
468 errorIfNotEqual(t, LNumber(0), values[0])
469 // cancel the parent context
470 cancel()
471 _, err, values = L.Resume(co, fn)
472 errorIfNil(t, err)
473 errorIfFalse(t, strings.Contains(err.Error(), "context canceled"), "coroutine execution must be canceled when the parent context is canceled")
474
475}
476
477func TestPCallAfterFail(t *testing.T) {
478 L := NewState()

Callers

nothing calls this directly

Calls 13

errorIfNotNilFunction · 0.85
errorIfNotEqualFunction · 0.85
LNumberTypeAlias · 0.85
errorIfNilFunction · 0.85
errorIfFalseFunction · 0.85
DoStringMethod · 0.80
NewStateFunction · 0.70
ErrorMethod · 0.65
CloseMethod · 0.45
SetContextMethod · 0.45
NewThreadMethod · 0.45
GetGlobalMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…