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

Function TestContextCancel

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

Source from the content-addressed store, hash-verified

422}
423
424func 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
447func TestContextWithCroutine(t *testing.T) {
448 L := NewState()

Callers

nothing calls this directly

Calls 7

errorIfNilFunction · 0.85
errorIfFalseFunction · 0.85
DoStringMethod · 0.80
NewStateFunction · 0.70
ErrorMethod · 0.65
CloseMethod · 0.45
SetContextMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…