feat(go): generate unique load simulator frames

This commit is contained in:
lingniu
2026-07-03 18:43:15 +08:00
parent 09f3e68891
commit 1cbe29c5fc
5 changed files with 340 additions and 12 deletions

View File

@@ -54,6 +54,48 @@ func TestRunnerDialsTargetConnectionsAndWritesFrames(t *testing.T) {
}
}
func TestRunnerWritesVariantFrames(t *testing.T) {
writes := make(chan []byte, 8)
runner := Runner{
Dial: func(ctx context.Context, network, addr string) (net.Conn, error) {
return &recordingConn{
write: func(p []byte) (int, error) {
cp := append([]byte(nil), p...)
select {
case writes <- cp:
default:
}
return len(p), nil
},
close: func() error { return nil },
}, nil
},
}
stats, err := runner.Run(context.Background(), Config{
Protocol: ProtocolJT808,
Addr: "127.0.0.1:808",
Connections: 1,
ConnectRatePerSecond: 1000,
SendInterval: time.Millisecond,
Duration: 6 * time.Millisecond,
Template: "0200",
SendFrames: true,
})
if err != nil {
t.Fatalf("Run() error = %v", err)
}
if stats.FramesWritten < 2 {
t.Fatalf("FramesWritten = %d, want at least 2", stats.FramesWritten)
}
first := <-writes
second := <-writes
if string(first) == string(second) {
t.Fatal("runner wrote byte-identical frames; want per-frame variants")
}
}
func TestRunnerCanHoldConnectionsWithoutWritingFrames(t *testing.T) {
var writes atomic.Int64
runner := Runner{