🔧 Update Go version in go.mod and enhance build process with versioning information. Modify Makefile and Taskfile to inject build metadata (version, commit, build time) into the binary. Improve README with instructions for custom version builds and document new build info features. Add benchmarks for message parsing and processing to improve performance testing capabilities.

This commit is contained in:
windyboy
2025-11-18 14:15:58 +08:00
parent 7f44b5389d
commit 06fc9cb9e0
27 changed files with 3009 additions and 55 deletions
+147
View File
@@ -0,0 +1,147 @@
package app
import (
"caatsm/internal/adapter/dto"
"caatsm/internal/adapter/parser"
"caatsm/internal/infra/telemetry"
"context"
"testing"
"go.uber.org/zap"
)
// Mock implementations for benchmarking
type mockRepository struct{}
func (m *mockRepository) InsertOne(ctx context.Context, msg *dto.ParsedTelegram) error {
return nil
}
func (m *mockRepository) InsertBatch(ctx context.Context, msgs []*dto.ParsedTelegram) error {
return nil
}
func (m *mockRepository) InsertRaw(ctx context.Context, msg *dto.ParsedTelegram) error {
return nil
}
type mockPublisher struct{}
func (m *mockPublisher) Publish(message interface{}) error {
return nil
}
// Benchmark data
var (
benchARRRaw = []byte(`ZCZC TMQ2526 141605
FF ZBTJZPZX
141604 ZBACZQZX
(ARR-JAE7433/A0132-RKSI-ZBTJ1604)
NNNN`)
benchDEPRaw = []byte(`ZCZC DEP5678 120915
DD KLAXZPZX
120914 KSFOZQZX
(DEP-ABC5678-A1234-ZBTJ1440-ZGGG)
NNNN`)
benchFPLRaw = []byte(`ZCZC TMQ2617 142150
GG ZBTJZPZX
150551 ZBTJUOBK
(FPL-OKA2861-IS
-MA60/M-SHID/C
-ZBTJ0030
-K0420S0450 CG J1 FZ
-ZSYT0100 ZSQD ZYTL
-REG/B3710 SEL/ RMK/TCAS )
NNNN`)
)
// createBenchmarkProcessor creates a processor with mocks for benchmarking
func createBenchmarkProcessor() *MessageProcessor {
aviationParser := parser.ProvideParser()
mockRepo := &mockRepository{}
mockPub := &mockPublisher{}
logger := zap.NewNop()
recorder := telemetry.NewNoop()
return NewMessageProcessor(aviationParser, mockRepo, mockPub, recorder, logger)
}
// BenchmarkHandleARR benchmarks processing ARR messages end-to-end
func BenchmarkHandleARR(b *testing.B) {
processor := createBenchmarkProcessor()
ctx := context.Background()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = processor.Handle(ctx, benchARRRaw, "msg-arr-123")
}
}
// BenchmarkHandleDEP benchmarks processing DEP messages end-to-end
func BenchmarkHandleDEP(b *testing.B) {
processor := createBenchmarkProcessor()
ctx := context.Background()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = processor.Handle(ctx, benchDEPRaw, "msg-dep-123")
}
}
// BenchmarkHandleFPL benchmarks processing FPL messages end-to-end
func BenchmarkHandleFPL(b *testing.B) {
processor := createBenchmarkProcessor()
ctx := context.Background()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = processor.Handle(ctx, benchFPLRaw, "msg-fpl-123")
}
}
// BenchmarkHandleMixed benchmarks processing a mix of message types
func BenchmarkHandleMixed(b *testing.B) {
processor := createBenchmarkProcessor()
ctx := context.Background()
messages := [][]byte{benchARRRaw, benchDEPRaw, benchFPLRaw}
msgIDs := []string{"msg-arr", "msg-dep", "msg-fpl"}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
idx := i % len(messages)
_ = processor.Handle(ctx, messages[idx], msgIDs[idx])
}
}
// BenchmarkHandleParseOnly benchmarks parsing without persistence/publishing
// This isolates parser performance
func BenchmarkHandleParseOnly(b *testing.B) {
aviationParser := parser.ProvideParser()
// Use a repository that does nothing
mockRepo := &mockRepository{}
// Use a publisher that does nothing
mockPub := &mockPublisher{}
logger := zap.NewNop()
recorder := telemetry.NewNoop()
processor := NewMessageProcessor(aviationParser, mockRepo, mockPub, recorder, logger)
ctx := context.Background()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = processor.Handle(ctx, benchARRRaw, "msg-parse-only")
}
}