5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 04:50:29 +00:00

fix core tests

This commit is contained in:
Arceliar 2021-07-07 18:36:51 -05:00
parent 3704ebf4cb
commit cd5383f7b7

View File

@ -44,13 +44,11 @@ func CreateAndConnectTwo(t testing.TB, verbose bool) (nodeA *Core, nodeB *Core)
if err := nodeA.Start(GenerateConfig(), GetLoggerWithPrefix("A: ", verbose)); err != nil { if err := nodeA.Start(GenerateConfig(), GetLoggerWithPrefix("A: ", verbose)); err != nil {
t.Fatal(err) t.Fatal(err)
} }
nodeA.SetMTU(1500)
nodeB = new(Core) nodeB = new(Core)
if err := nodeB.Start(GenerateConfig(), GetLoggerWithPrefix("B: ", verbose)); err != nil { if err := nodeB.Start(GenerateConfig(), GetLoggerWithPrefix("B: ", verbose)); err != nil {
t.Fatal(err) t.Fatal(err)
} }
nodeB.SetMTU(1500)
u, err := url.Parse("tcp://" + nodeA.links.tcp.getAddr().String()) u, err := url.Parse("tcp://" + nodeA.links.tcp.getAddr().String())
if err != nil { if err != nil {
@ -94,7 +92,7 @@ func CreateEchoListener(t testing.TB, nodeA *Core, bufLen int, repeats int) chan
buf := make([]byte, bufLen) buf := make([]byte, bufLen)
res := make([]byte, bufLen) res := make([]byte, bufLen)
for i := 0; i < repeats; i++ { for i := 0; i < repeats; i++ {
n, err := nodeA.Read(buf) n, from, err := nodeA.ReadFrom(buf)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return
@ -106,7 +104,7 @@ func CreateEchoListener(t testing.TB, nodeA *Core, bufLen int, repeats int) chan
copy(res, buf) copy(res, buf)
copy(res[8:24], buf[24:40]) copy(res[8:24], buf[24:40])
copy(res[24:40], buf[8:24]) copy(res[24:40], buf[8:24])
_, err = nodeA.Write(res) _, err = nodeA.WriteTo(res, from)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@ -141,12 +139,12 @@ func TestCore_Start_Transfer(t *testing.T) {
msg[0] = 0x60 msg[0] = 0x60
copy(msg[8:24], nodeB.Address()) copy(msg[8:24], nodeB.Address())
copy(msg[24:40], nodeA.Address()) copy(msg[24:40], nodeA.Address())
_, err := nodeB.Write(msg) _, err := nodeB.WriteTo(msg, nodeA.LocalAddr())
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
buf := make([]byte, msgLen) buf := make([]byte, msgLen)
_, err = nodeB.Read(buf) _, _, err = nodeB.ReadFrom(buf)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -179,12 +177,13 @@ func BenchmarkCore_Start_Transfer(b *testing.B) {
b.SetBytes(int64(msgLen)) b.SetBytes(int64(msgLen))
b.ResetTimer() b.ResetTimer()
addr := nodeA.LocalAddr()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_, err := nodeB.Write(msg) _, err := nodeB.WriteTo(msg, addr)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
_, err = nodeB.Read(buf) _, _, err = nodeB.ReadFrom(buf)
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }