(t *testing.T)
| 1270 | } |
| 1271 | |
| 1272 | func 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 | |
| 1316 | func TestContextInternalsCoverage(t *testing.T) { |
| 1317 | t.Run("ScheduleEdgeCases", func(t *testing.T) { |
nothing calls this directly
no test coverage detected