(t *testing.T)
| 1235 | } |
| 1236 | |
| 1237 | func TestContextEval(t *testing.T) { |
| 1238 | env := testEnv(t, Variable("items", ListType(IntType))) |
| 1239 | ast, iss := env.Compile("items.map(i, i * 2).filter(i, i >= 50).size()") |
| 1240 | if iss.Err() != nil { |
| 1241 | t.Fatalf("env.Compile(expr) failed: %v", iss.Err()) |
| 1242 | } |
| 1243 | prg, err := env.Program(ast, EvalOptions(OptOptimize|OptTrackState), InterruptCheckFrequency(100)) |
| 1244 | if err != nil { |
| 1245 | t.Fatalf("env.Program() failed: %v", err) |
| 1246 | } |
| 1247 | |
| 1248 | ctx := context.TODO() |
| 1249 | items := make([]int64, 2000) |
| 1250 | for i := int64(0); i < 2000; i++ { |
| 1251 | items[i] = i |
| 1252 | } |
| 1253 | out, _, err := prg.ContextEval(ctx, map[string]any{"items": items}) |
| 1254 | if err != nil { |
| 1255 | t.Fatalf("prg.ContextEval() failed: %v", err) |
| 1256 | } |
| 1257 | if out != types.Int(1975) { |
| 1258 | t.Errorf("prg.ContextEval() got %v, wanted 1975", out) |
| 1259 | } |
| 1260 | |
| 1261 | evalCtx, cancel := context.WithTimeout(ctx, time.Microsecond) |
| 1262 | defer cancel() |
| 1263 | |
| 1264 | out, _, err = prg.ContextEval(evalCtx, map[string]any{"items": items}) |
| 1265 | if err == nil { |
| 1266 | t.Errorf("Got result %v, wanted timeout error", out) |
| 1267 | } |
| 1268 | if err != nil && !errors.Is(err, context.DeadlineExceeded) { |
| 1269 | t.Errorf("Got %v, wanted context deadline exceeded", err) |
| 1270 | } |
| 1271 | if err != nil && !strings.Contains(err.Error(), "operation interrupted") { |
| 1272 | t.Errorf("Got %v, wanted error containing 'operation interrupted'", err) |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | func TestContextEvalUnknowns(t *testing.T) { |
| 1277 | env, err := NewEnv( |
nothing calls this directly
no test coverage detected