add good practice to save space of empty struct -> size of 0

pull/69/head
Minh Doan 6 years ago
parent 028512ad81
commit fa869b6974
  1. 8
      p2p/helper_test.go

@ -6,10 +6,10 @@ import (
"testing" "testing"
) )
func setUpTestServer(times int, t *testing.T, conCreated chan bool) { func setUpTestServer(times int, t *testing.T, conCreated chan struct{}) {
t.Parallel() t.Parallel()
ln, _ := net.Listen("tcp", ":8081") ln, _ := net.Listen("tcp", ":8081")
conCreated <- true conCreated <- struct{}{}
conn, _ := ln.Accept() conn, _ := ln.Accept()
defer conn.Close() defer conn.Close()
@ -29,11 +29,12 @@ func setUpTestServer(times int, t *testing.T, conCreated chan bool) {
} }
func TestNewNewNode(t *testing.T) { func TestNewNewNode(t *testing.T) {
times := 100 times := 100
conCreated := make(chan bool) conCreated := make(chan struct{})
go setUpTestServer(times, t, conCreated) go setUpTestServer(times, t, conCreated)
<-conCreated <-conCreated
conn, _ := net.Dial("tcp", "127.0.0.1:8081") conn, _ := net.Dial("tcp", "127.0.0.1:8081")
defer conn.Close()
for times > 0 { for times > 0 {
times-- times--
@ -49,5 +50,4 @@ func TestNewNewNode(t *testing.T) {
t.Error("did not receive expected message") t.Error("did not receive expected message")
} }
} }
conn.Close()
} }

Loading…
Cancel
Save