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

Function TestEnvConcurrentExtendAndCompile

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

Source from the content-addressed store, hash-verified

241}
242
243func TestEnvConcurrentExtendAndCompile(t *testing.T) {
244 t.Parallel()
245 baseEnv, err := NewCustomEnv(StdLib())
246 if err != nil {
247 t.Fatalf("NewCustomEnv() failed: %v", err)
248 }
249 var wg sync.WaitGroup
250 for i := 0; i < 50; i++ {
251 wg.Add(1)
252 go func(id int) {
253 defer wg.Done()
254 varName := fmt.Sprintf("v%d", id)
255 extEnv, err := baseEnv.Extend(Variable(varName, IntType))
256 if err != nil {
257 t.Errorf("Extend() failed: %v", err)
258 return
259 }
260 ast, iss := extEnv.Compile(fmt.Sprintf("%s > 0", varName))
261 if iss.Err() != nil {
262 t.Errorf("Compile() failed: %v", iss.Err())
263 return
264 }
265 prg, err := extEnv.Program(ast)
266 if err != nil {
267 t.Errorf("Program() failed: %v", err)
268 return
269 }
270 out, _, err := prg.Eval(map[string]any{varName: 10})
271 if err != nil {
272 t.Errorf("Eval() failed: %v", err)
273 return
274 }
275 if out.Value() != true {
276 t.Errorf("got %v, wanted true", out.Value())
277 }
278 }(i)
279 }
280 wg.Wait()
281}
282
283func TestEnvConcurrentExtendWithMutation(t *testing.T) {
284 t.Parallel()

Callers

nothing calls this directly

Calls 10

NewCustomEnvFunction · 0.85
StdLibFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
VariableFunction · 0.70
AddMethod · 0.65
CompileMethod · 0.65
EvalMethod · 0.65
ValueMethod · 0.65
ExtendMethod · 0.45

Tested by

no test coverage detected