跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

hostagent_test.go

63 行 · 1.4 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package main
5
6import (
7 "testing"
8 "testing/synctest"
9 "time"
10
11 "gotest.tools/v3/assert"
12)
13
14type countingSyncer struct {
15 writes, syncedWrites, syncs int
16}
17
18func (c *countingSyncer) Write(p []byte) (int, error) { c.writes++; return len(p), nil }
19func (c *countingSyncer) Sync() error {
20 c.syncedWrites = c.writes
21 c.syncs++
22 return nil
23}
24
25func TestSyncWriter(t *testing.T) {
26 synctest.Test(t, func(t *testing.T) {
27 c := &countingSyncer{}
28 w := &syncWriter{w: c}
29
30 const records = 1000
31 for range records {
32 _, err := w.Write([]byte("record\n"))
33 assert.NilError(t, err)
34 }
35 time.Sleep(syncInterval)
36 synctest.Wait()
37
38 assert.Equal(t, c.writes, records)
39 assert.Equal(t, c.syncedWrites, records)
40 assert.Equal(t, c.syncs, 1)
41
42 // A coalesced write must be synced even if the stream then goes idle.
43 _, err := w.Write([]byte("first\n"))
44 assert.NilError(t, err)
45 _, err = w.Write([]byte("second\n"))
46 assert.NilError(t, err)
47 time.Sleep(syncInterval)
48 synctest.Wait()
49
50 assert.Equal(t, c.syncedWrites, records+2)
51 assert.Equal(t, c.syncs, 2)
52
53 // Shutdown must flush immediately and stop the pending timer.
54 _, err = w.Write([]byte("record\n"))
55 assert.NilError(t, err)
56 w.flush()
57 time.Sleep(syncInterval)
58 synctest.Wait()
59
60 assert.Equal(t, c.syncedWrites, records+3)
61 assert.Equal(t, c.syncs, 3)
62 })
63}