Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel committed May 31, 2016
1 parent 474b879 commit 4b20de5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.6.1
- 1.6.2

sudo: false

Expand Down
2 changes: 2 additions & 0 deletions zk/dnshostprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ func TestDNSHostProviderReconnect(t *testing.T) {
// It's also probably the clearest visual explanation of exactly how
// it works.
func TestDNSHostProviderRetryStart(t *testing.T) {
t.Parallel()

hp := &DNSHostProvider{lookupHost: func(host string) ([]string, error) {
return []string{"192.0.2.1", "192.0.2.2", "192.0.2.3"}, nil
}}
Expand Down
3 changes: 3 additions & 0 deletions zk/flw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Node count: 306
)

func TestFLWRuok(t *testing.T) {
t.Parallel()
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -62,6 +63,7 @@ func TestFLWRuok(t *testing.T) {
}

func TestFLWSrvr(t *testing.T) {
t.Parallel()
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -134,6 +136,7 @@ func TestFLWSrvr(t *testing.T) {
}

func TestFLWCons(t *testing.T) {
t.Parallel()
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
Expand Down
16 changes: 10 additions & 6 deletions zk/server_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"time"
)

func init() {
rand.Seed(time.Now().UnixNano())
}

type TestServer struct {
Port int
Path string
Expand Down Expand Up @@ -88,7 +92,7 @@ func StartTestCluster(size int, stdout, stderr io.Writer) (*TestCluster, error)
Srv: srv,
})
}
if err := cluster.waitForStart(5, time.Second); err != nil {
if err := cluster.waitForStart(10, time.Second); err != nil {
return nil, err
}
success = true
Expand Down Expand Up @@ -118,10 +122,10 @@ func (ts *TestCluster) Stop() error {
srv.Srv.Stop()
}
defer os.RemoveAll(ts.Path)
return ts.waitForStop(5, 1*time.Second)
return ts.waitForStop(5, time.Second)
}

// block until the cluster is up
// waitForStart blocks until the cluster is up
func (ts *TestCluster) waitForStart(maxRetry int, interval time.Duration) error {
// verify that the servers are up with SRVR
serverAddrs := make([]string, len(ts.Servers))
Expand All @@ -136,10 +140,10 @@ func (ts *TestCluster) waitForStart(maxRetry int, interval time.Duration) error
}
time.Sleep(interval)
}
return fmt.Errorf("unable to verify health of servers!")
return fmt.Errorf("unable to verify health of servers")
}

// block until the cluster is down
// waitForStop blocks until the cluster is down
func (ts *TestCluster) waitForStop(maxRetry int, interval time.Duration) error {
// verify that the servers are up with RUOK
serverAddrs := make([]string, len(ts.Servers))
Expand All @@ -160,7 +164,7 @@ func (ts *TestCluster) waitForStop(maxRetry int, interval time.Duration) error {
}
}
if !success {
return fmt.Errorf("unable to verify servers are down!")
return fmt.Errorf("unable to verify servers are down")
}
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions zk/structs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

func TestEncodeDecodePacket(t *testing.T) {
t.Parallel()
encodeDecodeTest(t, &requestHeader{-2, 5})
encodeDecodeTest(t, &connectResponse{1, 2, 3, nil})
encodeDecodeTest(t, &connectResponse{1, 2, 3, []byte{4, 5, 6}})
Expand Down Expand Up @@ -42,6 +43,7 @@ func encodeDecodeTest(t *testing.T, r interface{}) {
}

func TestEncodeShortBuffer(t *testing.T) {
t.Parallel()
buf := make([]byte, 0)
_, err := encodePacket(buf, &requestHeader{1, 2})
if err != ErrShortBuffer {
Expand All @@ -51,6 +53,7 @@ func TestEncodeShortBuffer(t *testing.T) {
}

func TestDecodeShortBuffer(t *testing.T) {
t.Parallel()
buf := make([]byte, 0)
_, err := decodePacket(buf, &responseHeader{})
if err != ErrShortBuffer {
Expand All @@ -63,6 +66,7 @@ func BenchmarkEncode(b *testing.B) {
buf := make([]byte, 4096)
st := &connectRequest{Passwd: []byte("1234567890")}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := encodePacket(buf, st); err != nil {
b.Fatal(err)
Expand Down
11 changes: 4 additions & 7 deletions zk/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ package zk
import "testing"

func TestFormatServers(t *testing.T) {
t.Parallel()
servers := []string{"127.0.0.1:2181", "127.0.0.42", "127.0.42.1:8811"}
r := []string{"127.0.0.1:2181", "127.0.0.42:2181", "127.0.42.1:8811"}

var s []string
s = FormatServers(servers)

for i := range s {
if s[i] != r[i] {
t.Errorf("%v should equal %v", s[i], r[i])
for i, s := range FormatServers(servers) {
if s != r[i] {
t.Errorf("%v should equal %v", s, r[i])
}
}
}

0 comments on commit 4b20de5

Please sign in to comment.