MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestEnvConcurrentExtendWithMutation

Function TestEnvConcurrentExtendWithMutation

cel/env_test.go:282–328  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

280}
281
282func TestEnvConcurrentExtendWithMutation(t *testing.T) {
283 t.Parallel()
284 baseEnv, err := NewCustomEnv(StdLib())
285 if err != nil {
286 t.Fatalf("NewCustomEnv() failed: %v", err)
287 }
288 var wg sync.WaitGroup
289 for i := 0; i < 50; i++ {
290 wg.Add(1)
291 go func(id int) {
292 defer wg.Done()
293 fnName := fmt.Sprintf("custom_func_%d", id)
294 extEnv, err := baseEnv.Extend(
295 Function(fnName,
296 Overload(fnName+"_int", []*Type{IntType}, IntType,
297 UnaryBinding(func(val ref.Val) ref.Val {
298 return val
299 }),
300 ),
301 ),
302 )
303 if err != nil {
304 t.Errorf("Extend() failed: %v", err)
305 return
306 }
307 ast, iss := extEnv.Compile(fmt.Sprintf("%s(42) == 42", fnName))
308 if iss.Err() != nil {
309 t.Errorf("Compile() failed: %v", iss.Err())
310 return
311 }
312 prg, err := extEnv.Program(ast)
313 if err != nil {
314 t.Errorf("Program() failed: %v", err)
315 return
316 }
317 out, _, err := prg.Eval(NoVars())
318 if err != nil {
319 t.Errorf("Eval() failed: %v", err)
320 return
321 }
322 if out.Value() != true {
323 t.Errorf("got %v, wanted true", out.Value())
324 }
325 }(i)
326 }
327 wg.Wait()
328}
329
330func TestEnvPartialVarsError(t *testing.T) {
331 env := testEnv(t)

Callers

nothing calls this directly

Calls 13

NewCustomEnvFunction · 0.85
StdLibFunction · 0.85
NoVarsFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
FunctionFunction · 0.70
OverloadFunction · 0.70
UnaryBindingFunction · 0.70
AddMethod · 0.65
CompileMethod · 0.65
EvalMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected