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

Function TestEnvConcurrentExtendAndCompile

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

Source from the content-addressed store, hash-verified

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