test

command
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 9 Imported by: 0

README

test/ 目录说明

本目录存放联调脚本、抓包样本、驱动手工测试笔记及配置归档。运行时网关以数据库为配置源(internal/configdata/config.db),下列文件不直接被 go test 加载,供文档引用、手工联调或导入参考。

目录结构

路径 说明
legacy/ 已废弃配置格式与全量快照归档
manual/ 驱动联调/验收笔记(BACnet、EtherNet/IP 等)
verify_bacnet.go BACnet API 联调脚本
test_api.sh HTTP API 冒烟脚本
test_ethernet-ip.py · ethernet_ip_server_v3.py EtherNet/IP 模拟器与联调脚本
ice104-python-server/ IEC 104 Python 模拟从站
slave1_points.json Modbus 从站 1 点位 JSON 样本
*.pcap · *.pcapng BACnet 发现/Who-Is 抓包样本
上位机监控表PLC.csv S7/PLC 点位导入样本

说明:根目录曾有的 v2 示例 YAML(config_v2_three_level.yamlconfig_multi_slave.yamlchannels.yaml)已移除,避免与 docs/deployment/conf/ 示例重复。现行 schema 与片段见下方「配置参考」;历史全量见 legacy/

配置参考(v2 三级架构)

运行时以 data/config.db 为准;下列为文档与联调用的参考来源,非 CI 依赖。

来源 用途
三级架构快速入门 v2 channelsdevicespoints 标准说明与 API 示例
多从站指南 同通道多 slave_id 配置与 BatchAddModbusSlaves
产品说明 — 配置结构 BACnet 等通道 YAML 片段
legacy/config_full_snapshot.yaml.bak 联调网关配置导出备份(全量 v2 快照,非 schema 模板)
legacy/config_multi_slave_legacy.yaml 2026-01 devices + slaves: 嵌套格式(已废弃)
v2 schema 要点
channels:                          # 第一级:采集通道(驱动 + 连接参数)
  - id: "modbus-tcp-1"
    protocol: "modbus-tcp"
    config:
      url: "tcp://127.0.0.1:502"
    devices:                       # 第二级:从站/设备(每 slave_id 一个 Device)
      - id: "slave-1"
        interval: 5s
        config:
          slave_id: 1              # Modbus Unit ID
        points:                    # 第三级:点位
          - id: "dev1_temp"
            address: "40001"
            datatype: "int16"

采集由 ScanEngine 按 Device interval 调度;同通道多从站通过 config.slave_id + 驱动内 SetSlaveID 实现。

Legacy 归档

已废弃的 devices + slaves: 嵌套格式及全量配置快照见 legacy/

文件 说明
legacy/config_multi_slave_legacy.yaml 原 2026-01 多从站嵌套格式
legacy/config_full_snapshot.yaml.bak 联调/手工测试时的网关配置导出备份

请勿用于新部署或 CI。

常用 go test 命令

单元测试覆盖率门禁(2026-07-05)

门禁阈值internal/core 语句覆盖率 ≥ 60%-short 友好)。

CGO_ENABLED=0 go test ./internal/core/... -short -count=1 -coverprofile=/tmp/core_cover.out
go tool cover -func=/tmp/core_cover.out | tail -1
阈值 实测(2026-07-05)
internal/core 语句覆盖率 ≥ 60% 80.6%

明细见 ScanEngine重构测试报告 §2.8南向驱动测试报告 §八

南向采集通道回归(2026-07-04 门禁)

南向采集通道回归验证测试方案 §五 一致;日志输出至 docs/testing/_run_logs/

# Week1 自动化 gate(按序执行)
CGO_ENABLED=0 go test ./internal/core/... -short -count=1
CGO_ENABLED=0 go test ./internal/driver/... -short -count=1
CGO_ENABLED=0 go test ./internal/integration/... -short -count=1
make test-soak-short          # SOAK_DURATION=30 可覆盖
make bench-q3
make bench-g007
命令 2026-07-04 结果 说明
core -short ✅ PASS ScanEngine / ShadowCore
driver -short ⚠️ FAIL(根包 1 用例) 子包全 PASS
integration -short ✅ PASS 集成冒烟
make test-soak-short ✅ PASS 五 gate
make bench-q3 ✅ PASS 10k tag deadline
make bench-g007 ⚠️ WARN ≥950 设备/秒边界

联机回归(A–G)步骤与排期见方案 §八;资产见本目录 manual/legacy/

默认 CI 友好包(与用户验收命令一致):

# 核心 + BACnet + SNMP + 配置(-short 跳过长跑/压测)
CGO_ENABLED=0 go test ./internal/core/... \
  ./internal/driver/bacnet/... \
  ./internal/driver/snmp/... \
  ./internal/config/... \
  -short -count=1

Makefile 目标(make 在仓库根目录):

命令 说明
make test-short internal/core + internal/integration-short
make test 同上,含长跑用例(无 -short
make test-soak-short Soak 短门控(默认 ~30s,SOAK_DURATION 可覆盖)
make test-soak 完整 Soak(-tags=soak,默认 1h,timeout=2h
make bench-q3 万 Tag Q3 压测(TestQ3_TenThousandTagBenchmark

其他常用片段:

# 全仓(macOS 上 internal/server、internal/sync 等可能因 TLS 链接失败)
CGO_ENABLED=0 go test ./... -short -count=1

# 仅集成层短测
CGO_ENABLED=0 go test ./internal/integration/... -short -count=1

# Q3 万 Tag 基准(非 short)
CGO_ENABLED=0 go test ./internal/core/ -run TestQ3_TenThousandTagBenchmark -count=1 -timeout=15m

相关文档

测试维护原则

CI 与本地 go test ./...现行实现为准。测试腐化时按下列规则处理,勿留占位或重复:

情况 处理
永久 t.Skip / 空函数体占位 删除
同包重复测试函数名 合并或删弱版,保留更有价值的断言
测试已移除的 production 符号 删除或改测 ScanEngine / 驱动现行路径
coverage_test.go 断言与实现不一致 以实现为准更新断言,或删无效 case
引用 legacy 配置(devices + slaves: 等) 改用 v2 示例,或归档至 test/legacy/
驱动 //go:build manual 保留,供手工联调,不参与默认 CI

macOS 链接失败(SecTrustCopyCertificateChain:Go 工具链与 macOS SDK 版本不匹配所致,非业务代码问题。升级 Go / Xcode Command Line Tools,或在 Linux CI 上跑全量测试;internal/serverinternal/sync 等依赖 TLS 的包在旧 macOS 上可能无法链接。

边缘计算压测(2026-07-05)

CGO_ENABLED=0 go test ./internal/core/ -run EdgeComputeStress -count=1 -timeout 180s -v
CGO_ENABLED=0 go test ./internal/core/ -run '^$' -bench=BenchmarkEdgeCompute -benchtime=1s -count=1
场景 关键指标 实测
高频合并 1000 次/100ms 窗口 executed / coalesced 1 / 999
100 规则 burst executed / dropped 100 / 0
内存稳定 5000 迭代 window_samples / cache 641 / 1(≤ cap)
延迟 p50/p99 SLA <100ms 0ms / 2ms
队列丢弃 failures 记录 drops=29 → failures=29
handleValue bench ns/op ~1223 ns/op

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL