feat: build vehicle data platform and production pipeline
This commit is contained in:
@@ -131,6 +131,48 @@ func TestRunnerCanHoldConnectionsWithoutWritingFrames(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerDrainsProtocolResponses(t *testing.T) {
|
||||
runner := Runner{
|
||||
Dial: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
client, server := net.Pipe()
|
||||
go func() {
|
||||
defer server.Close()
|
||||
buffer := make([]byte, 4096)
|
||||
for {
|
||||
if _, err := server.Read(buffer); err != nil {
|
||||
return
|
||||
}
|
||||
if _, err := server.Write([]byte{0x7e, 0x80, 0x01, 0x7e}); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
return client, nil
|
||||
},
|
||||
}
|
||||
|
||||
stats, err := runner.Run(context.Background(), Config{
|
||||
Protocol: ProtocolJT808,
|
||||
Addr: "127.0.0.1:808",
|
||||
Connections: 1,
|
||||
ConnectRatePerSecond: 1000,
|
||||
SendInterval: time.Millisecond,
|
||||
Duration: 10 * time.Millisecond,
|
||||
Template: "0200",
|
||||
SendFrames: true,
|
||||
DrainResponses: true,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
if stats.ResponseBytes == 0 {
|
||||
t.Fatalf("ResponseBytes = 0, want drained protocol responses")
|
||||
}
|
||||
if stats.ReadErrors != 0 {
|
||||
t.Fatalf("ReadErrors = %d, want 0", stats.ReadErrors)
|
||||
}
|
||||
}
|
||||
|
||||
type recordingConn struct {
|
||||
write func([]byte) (int, error)
|
||||
close func() error
|
||||
|
||||
Reference in New Issue
Block a user