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

Function FakeRPC

test/async.go:27–39  ·  view source on GitHub ↗

FakeRPC returns a blocking async function which simulates an RPC that succeeds after a short delay, or fails if the provided per-call timeout elapses first.

(timeout time.Duration)

Source from the content-addressed store, hash-verified

25// FakeRPC returns a blocking async function which simulates an RPC that succeeds after a short
26// delay, or fails if the provided per-call timeout elapses first.
27func FakeRPC(timeout time.Duration) func(context.Context, ...ref.Val) ref.Val {
28 return func(ctx context.Context, args ...ref.Val) ref.Val {
29 rpcCtx, cancel := context.WithTimeout(ctx, timeout)
30 defer cancel()
31 select {
32 case <-time.After(20 * time.Millisecond):
33 in := args[0].(types.String)
34 return in.Add(types.String(" success!"))
35 case <-rpcCtx.Done():
36 return types.NewErr(rpcCtx.Err().Error())
37 }
38 }
39}

Callers 1

TestConcurrentEvalFunction · 0.92

Calls 5

StringTypeAlias · 0.92
NewErrFunction · 0.92
ErrMethod · 0.80
AddMethod · 0.65
ErrorMethod · 0.45

Tested by 1

TestConcurrentEvalFunction · 0.74