feat(go): generate unique load simulator frames
This commit is contained in:
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user