MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestContextScheduler

Function TestContextScheduler

context_test.go:1272–1314  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1270}
1271
1272func TestContextScheduler(t *testing.T) {
1273 useStableOwnerHooksForLegacySubtests(t)
1274
1275 rt := NewRuntime()
1276 defer rt.Close()
1277 ctx := rt.NewContext()
1278 defer ctx.Close()
1279
1280 t.Run("LoopProcessesScheduledJobs", func(t *testing.T) {
1281 results := make(chan struct {
1282 sum int32
1283 err error
1284 }, 1)
1285
1286 require.True(t, ctx.Schedule(func(inner *Context) {
1287 val := inner.Eval(`40 + 2`)
1288 defer val.Free()
1289
1290 if val.IsException() {
1291 results <- struct {
1292 sum int32
1293 err error
1294 }{err: inner.Exception()}
1295 return
1296 }
1297
1298 results <- struct {
1299 sum int32
1300 err error
1301 }{sum: int32(val.ToInt32())}
1302 }))
1303
1304 ctx.Loop()
1305
1306 select {
1307 case res := <-results:
1308 require.NoError(t, res.err)
1309 require.Equal(t, int32(42), res.sum)
1310 case <-time.After(200 * time.Millisecond):
1311 t.Fatal("scheduled job was not executed")
1312 }
1313 })
1314}
1315
1316func TestContextInternalsCoverage(t *testing.T) {
1317 t.Run("ScheduleEdgeCases", func(t *testing.T) {

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
NewContextMethod · 0.95
CloseMethod · 0.95
ScheduleMethod · 0.95
LoopMethod · 0.95
NewRuntimeFunction · 0.85
EvalMethod · 0.80
IsExceptionMethod · 0.80
ExceptionMethod · 0.80
ToInt32Method · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected