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

Function TestEnvConcurrentExtendWithMutation

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

Source from the content-addressed store, hash-verified

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

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