Test two consecutive METADAPT-A writers
This commit is contained in:
parent
5341563668
commit
7d189df741
@ -152,12 +152,14 @@ func TestReadWriteA(test *testing.T) {
|
||||
gotPayloadBytes, err := io.ReadAll(gotReader)
|
||||
if err != nil { test.Fatal("CLIENT", err) }
|
||||
gotPayload := string(gotPayloadBytes)
|
||||
test.Log("CLIENT m:", gotMethod, "p:", gotPayload)
|
||||
test.Log("CLIENT m:", gotMethod, "p:", tu.HexBytes(gotPayloadBytes))
|
||||
if int(gotMethod) != method {
|
||||
test.Errorf("CLIENT method not equal")
|
||||
test.Error("CLIENT method not equal, expected", method)
|
||||
}
|
||||
if gotPayload != payload {
|
||||
test.Errorf("CLIENT payload not equal")
|
||||
test.Error(
|
||||
"CLIENT payload not equal, expected",
|
||||
tu.HexBytes([]byte(payload)))
|
||||
}
|
||||
}
|
||||
test.Log("CLIENT waiting for transaction close...")
|
||||
@ -165,8 +167,8 @@ func TestReadWriteA(test *testing.T) {
|
||||
if !errors.Is(err, io.EOF) {
|
||||
test.Error("CLIENT wrong error:", err)
|
||||
test.Error("CLIENT method:", gotMethod)
|
||||
test.Error("CLIENT payload:", gotPayload)
|
||||
test.Fatal("CLIENT ok byeeeeeeeeeeeee")
|
||||
test.Error("CLIENT payload:", tu.HexBytes(gotPayload))
|
||||
test.Fatal("CLIENT (expected io.EOF and no message)")
|
||||
}
|
||||
test.Log("CLIENT transaction has closed")
|
||||
}
|
||||
@ -177,7 +179,7 @@ func TestReadWriteA(test *testing.T) {
|
||||
if err != nil { test.Error("SERVER", err); return }
|
||||
test.Cleanup(func() { trans.Close() })
|
||||
for method, payload := range payloads {
|
||||
test.Log("SERVER m:", method, "p:", payload)
|
||||
test.Log("SERVER m:", method, "p:", tu.HexBytes([]byte(payload)))
|
||||
func() {
|
||||
writer, err := trans.SendWriter(uint16(method))
|
||||
if err != nil { test.Error("SERVER", err); return }
|
||||
@ -274,7 +276,7 @@ func TestEncodeDecodeMessageA(test *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConsecutiveWrite(test *testing.T) {
|
||||
func TestConsecutiveSend(test *testing.T) {
|
||||
packets := [][]byte {
|
||||
[]byte {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
@ -343,7 +345,81 @@ func TestConsecutiveWrite(test *testing.T) {
|
||||
group.Wait()
|
||||
}
|
||||
|
||||
func TestConsecutiveRead(test *testing.T) {
|
||||
func TestConsecutiveWrite(test *testing.T) {
|
||||
packets := [][]byte {
|
||||
[]byte {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
|
||||
0x43, 0x00, 0x00, 0x00, 0x07 },
|
||||
|
||||
[]byte {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
|
||||
0x43, 0x00, 0x00, 0x00, 0x08 },
|
||||
}
|
||||
payloads := [][]byte {
|
||||
[]byte { 0x43, 0x00, 0x00, 0x00, 0x07 },
|
||||
[]byte { 0x43, 0x00, 0x00, 0x00, 0x08 },
|
||||
}
|
||||
|
||||
var group sync.WaitGroup
|
||||
group.Add(2)
|
||||
|
||||
// server
|
||||
listener, err := net.Listen("tcp", "localhost:9999")
|
||||
if err != nil { test.Fatal("SERVER", err) }
|
||||
go func() {
|
||||
defer group.Done()
|
||||
defer listener.Close()
|
||||
conn, err := listener.Accept()
|
||||
if err != nil { test.Fatal("SERVER", err) }
|
||||
defer conn.Close()
|
||||
|
||||
buf := [16]byte { }
|
||||
for {
|
||||
_, err := conn.Read(buf[:])
|
||||
if err != nil { break }
|
||||
}
|
||||
}()
|
||||
|
||||
// client
|
||||
go func() {
|
||||
defer group.Done()
|
||||
conn, err := net.Dial("tcp", "localhost:9999")
|
||||
if err != nil { test.Fatal("CLIENT", err) }
|
||||
defer conn.Close()
|
||||
recorder := tu.RecordConn(conn)
|
||||
|
||||
a := AdaptA(recorder, ClientSide)
|
||||
trans, err := a.OpenTrans()
|
||||
if err != nil { test.Fatal("CLIENT", err) }
|
||||
|
||||
for _, payload := range payloads {
|
||||
func() {
|
||||
writer, err := trans.SendWriter(0x0000)
|
||||
if err != nil { test.Fatal("CLIENT", err) }
|
||||
_, err = writer.Write(payload)
|
||||
if err != nil { test.Fatal("CLIENT", err) }
|
||||
writer.Close()
|
||||
}()
|
||||
}
|
||||
|
||||
test.Log("CLIENT recorded output:\n" + recorder.Dump())
|
||||
if len(recorder.Log) != 2 { test.Fatal("wrong length") }
|
||||
if !slices.Equal(recorder.Log[0].([]byte), packets[0]) {
|
||||
test.Fatal("not equal")
|
||||
}
|
||||
if !slices.Equal(recorder.Log[1].([]byte), packets[1]) {
|
||||
test.Fatal("not equal")
|
||||
}
|
||||
}()
|
||||
|
||||
group.Wait()
|
||||
}
|
||||
|
||||
func TestConsecutiveReceive(test *testing.T) {
|
||||
stream := []byte {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user