From 1efac70cdbf912d024aa4ac862d1d6cf6a8f7d2c Mon Sep 17 00:00:00 2001 From: goldensea Date: Wed, 3 Dec 2025 19:38:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=8B=E6=B5=8B=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/gamelog/test/gamelog_test.go | 53 +++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/package/gamelog/test/gamelog_test.go b/package/gamelog/test/gamelog_test.go index 6e648bd..354662f 100644 --- a/package/gamelog/test/gamelog_test.go +++ b/package/gamelog/test/gamelog_test.go @@ -16,7 +16,8 @@ func TestGamelog(t *testing.T) { // 必填 Pid: "test5", // 项目ID // BaseUrl: "http://47.76.178.47:10101", // 香港测试服上报地址 - BaseUrl: "http://101.37.28.111:10101", // 香港测试服上报地址 + // BaseUrl: "http://101.37.28.111:10101", // 香港测试服上报地址 + BaseUrl: "http://47.77.200.131:10101", // 美国BIDB服务器 // BaseUrl: "http://127.0.0.1:10101", // 本次测试上报地址 ReportSk: "sngame2025", // xor混淆key FlushInterval: 5, // 上报间隔 @@ -52,3 +53,53 @@ func TestGamelog(t *testing.T) { glsdk.Shutdown() }) } + +func TestPressMQ(t *testing.T) { + glsdk, err := gamelog.INIT(&gamelog.SDKConfig{ + // 必填 + Pid: "yotest", // 项目ID + BaseUrl: "http://47.77.200.131:10101", // 美国BIDB服务器 + ReportSk: "sngame2025", // xor混淆key + FlushInterval: 6, // 上报间隔 + DiskBakPath: "gamelog", // 本地磁盘备份, 用于意外情况下临时保存日志, 请确保该目录持久化(容器内要挂载). 每次启动时或每N次上报时加载到失败队列 + // 可填 + RetryN: 2, // 默认每10次, 上传检查一次磁盘的失败数据 + ChanSize: 500, // 默认1000, 信道size + SendSaveType: 2, // 发送存储类型, 默认不设置为0代表文件存储, 2代表走kafka可实同步日志 + }) + + // 随机测试事件和属性 + events := []string{"e1", "e2", "e3", "e4"} + pms := []map[string]any{ + {"a": "1"}, + {"a": "2"}, + {"a": "3"}, + {"a": "4"}, + } + uuids := []string{} + for i := 0; i < 100; i++ { + uuidval, _ := uuid.NewUUID() + randUid := strings.ReplaceAll(uuidval.String(), "-", "") + uuids = append(uuids, randUid) + } + if err != nil { + t.Fatal(err) + } + n := 0 + const limit = 30000 + gtest.C(t, func(t *gtest.T) { + go func() { + for { + glsdk.LogLtz(uuids[grand.Intn(len(uuids))], events[grand.Intn(len(events))], pms[grand.Intn(len(pms))]) + // 并发控制 + n++ + if n%limit == 0 { + time.Sleep(time.Second * 1) + } + } + }() + time.Sleep(time.Second * 120) + // 模拟等待信号后优雅关闭 + glsdk.Shutdown() + }) +}