MCPcopy Create free account
hub / github.com/dagger/dagger / TestImplicitInputCachePerSession

Function TestImplicitInputCachePerSession

dagql/dagql_test.go:2851–2880  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2849}
2850
2851func TestImplicitInputCachePerSession(t *testing.T) {
2852 srv := newExternalDagqlServerForTest(t, Query{})
2853 cache := newCache(t)
2854
2855 var calls atomic.Int64
2856 dagql.Fields[Query]{
2857 dagql.NodeFunc("perSessionCounter", func(ctx context.Context, _ dagql.ObjectResult[Query], _ struct{}) (int, error) {
2858 return int(calls.Add(1)), nil
2859 }).WithInput(dagql.PerSessionInput),
2860 }.Install(srv)
2861
2862 callForSession := func(sessionID string) int {
2863 ctx := engine.ContextWithClientMetadata(context.Background(), &engine.ClientMetadata{
2864 ClientID: "same-client",
2865 SessionID: sessionID,
2866 })
2867 ctx = dagql.ContextWithCache(ctx, cache)
2868 var res int
2869 err := srv.Select(ctx, srv.Root(), &res, dagql.Selector{
2870 Field: "perSessionCounter",
2871 })
2872 require.NoError(t, err)
2873 return res
2874 }
2875
2876 assert.Equal(t, callForSession("session-a"), 1)
2877 assert.Equal(t, callForSession("session-a"), 1)
2878 assert.Equal(t, callForSession("session-b"), 2)
2879 assert.Equal(t, callForSession("session-b"), 2)
2880}
2881
2882func TestImplicitInputCachePerCall(t *testing.T) {
2883 srv := newExternalDagqlServerForTest(t, Query{})

Callers

nothing calls this directly

Calls 12

NodeFuncFunction · 0.92
ContextWithCacheFunction · 0.92
newCacheFunction · 0.70
InstallMethod · 0.65
AddMethod · 0.65
BackgroundMethod · 0.65
SelectMethod · 0.65
EqualMethod · 0.65
WithInputMethod · 0.45
RootMethod · 0.45

Tested by

no test coverage detected