MCPcopy Create free account
hub / github.com/astercloud/aster / TestWorkingMemoryManager_TTL

Function TestWorkingMemoryManager_TTL

pkg/memory/working_test.go:176–217  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

174}
175
176func TestWorkingMemoryManager_TTL(t *testing.T) {
177 ctx := context.Background()
178 backend := backends.NewStateBackend()
179
180 // 创建带 TTL 的管理器(1 秒过期)
181 manager, err := NewWorkingMemoryManager(&WorkingMemoryConfig{
182 Backend: backend,
183 BasePath: "/working_memory/",
184 Scope: ScopeThread,
185 DefaultTTL: 1 * time.Second,
186 })
187 if err != nil {
188 t.Fatalf("create manager: %v", err)
189 }
190
191 threadID := "test-thread"
192 resourceID := "test-resource"
193
194 // 更新内容
195 err = manager.Update(ctx, threadID, resourceID, "Temporary content")
196 if err != nil {
197 t.Fatalf("update: %v", err)
198 }
199
200 // 立即读取应该成功
201 content, _ := manager.Get(ctx, threadID, resourceID)
202 if content == "" {
203 t.Error("expected content immediately after update")
204 }
205
206 // 等待过期
207 time.Sleep(2 * time.Second)
208
209 // 过期后应该返回空
210 content, err = manager.Get(ctx, threadID, resourceID)
211 if err != nil {
212 t.Fatalf("get after expiry: %v", err)
213 }
214 if content != "" {
215 t.Errorf("expected empty content after expiry, got: %s", content)
216 }
217}
218
219func TestWorkingMemoryManager_Schema(t *testing.T) {
220 ctx := context.Background()

Callers

nothing calls this directly

Calls 5

UpdateMethod · 0.95
GetMethod · 0.95
NewStateBackendFunction · 0.92
NewWorkingMemoryManagerFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected