feat(go): add load simulator hold mode
This commit is contained in:
@@ -34,6 +34,7 @@ func TestRunnerDialsTargetConnectionsAndWritesFrames(t *testing.T) {
|
||||
SendInterval: time.Millisecond,
|
||||
Duration: 5 * time.Millisecond,
|
||||
Template: "0200",
|
||||
SendFrames: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
@@ -53,6 +54,41 @@ func TestRunnerDialsTargetConnectionsAndWritesFrames(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerCanHoldConnectionsWithoutWritingFrames(t *testing.T) {
|
||||
var writes atomic.Int64
|
||||
runner := Runner{
|
||||
Dial: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return &recordingConn{
|
||||
write: func(p []byte) (int, error) {
|
||||
writes.Add(1)
|
||||
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: 2,
|
||||
ConnectRatePerSecond: 1000,
|
||||
SendInterval: time.Millisecond,
|
||||
Duration: 5 * time.Millisecond,
|
||||
Template: "0200",
|
||||
SendFrames: false,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
if stats.ConnectionsOpened != 2 {
|
||||
t.Fatalf("ConnectionsOpened = %d, want 2", stats.ConnectionsOpened)
|
||||
}
|
||||
if stats.FramesWritten != 0 || writes.Load() != 0 {
|
||||
t.Fatalf("frames written stats=%d writes=%d, want 0", stats.FramesWritten, writes.Load())
|
||||
}
|
||||
}
|
||||
|
||||
type recordingConn struct {
|
||||
write func([]byte) (int, error)
|
||||
close func() error
|
||||
|
||||
Reference in New Issue
Block a user