Skip to content

Commit

Permalink
Merge branch 'master' into badge
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbean authored Apr 14, 2024
2 parents b32ffa4 + 2480e3d commit e6155c8
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
33 changes: 33 additions & 0 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: integration_test
on: [push, pull_request]

jobs:
integration_test:
name: integration_test
strategy:
matrix:
zk-version: [3.5.8, 3.6.1]
go-version: ['oldstable', 'stable']
runs-on: ubuntu-latest
steps:
- name: Go ${{ matrix.go }} setup
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Setup Java 14
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 14

- name: Checkout code
uses: actions/checkout@v3

- name: Test code
run: make test ZK_VERSION=${{ matrix.zk-version }}

- name: Upload code coverage
uses: codecov/codecov-action@v1
with:
file: ./profile.cov
23 changes: 6 additions & 17 deletions .github/workflows/unittest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,16 @@ jobs:
name: unittest
strategy:
matrix:
zk-version: [3.5.8, 3.6.1]
go-version: [1.13.x, 1.14.x]
go-version: ['oldstable', 'stable']
runs-on: ubuntu-latest
steps:
- name: Setup Go
uses: actions/setup-go@v1
- name: Go ${{ matrix.go }} setup
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: 14

- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@v3

- name: Test code
run: make test ZK_VERSION=${{ matrix.zk-version }}

- name: Upload code coverage
uses: codecov/codecov-action@v1
with:
file: ./profile.cov
- name: Run unittest ${{ matrix.go }}
run: make unittest
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ lint:
build:
go build ./...

.PHONY: unittest
unittest:
go test -timeout 500s -v -race -covermode atomic -skip=Integration ./...

.PHONY: test
test: build zookeeper
go test -timeout 500s -v -race -covermode atomic -coverprofile=profile.cov $(PACKAGES)
Expand Down
12 changes: 5 additions & 7 deletions cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (lw logWriter) Write(b []byte) (int, error) {
return len(b), nil
}

func TestBasicCluster(t *testing.T) {
func TestIntegration_BasicCluster(t *testing.T) {
ts, err := StartTestCluster(t, 3, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
t.Fatal(err)
Expand All @@ -33,8 +33,6 @@ func TestBasicCluster(t *testing.T) {
}
defer zk2.Close()

time.Sleep(time.Second * 5)

if _, err := zk1.Create("/gozk-test", []byte("foo-cluster"), 0, WorldACL(PermAll)); err != nil {
t.Fatalf("Create failed on node 1: %+v", err)
}
Expand All @@ -51,7 +49,7 @@ func TestBasicCluster(t *testing.T) {
}

// If the current leader dies, then the session is reestablished with the new one.
func TestClientClusterFailover(t *testing.T) {
func TestIntegration_ClientClusterFailover(t *testing.T) {
tc, err := StartTestCluster(t, 3, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -93,7 +91,7 @@ func TestClientClusterFailover(t *testing.T) {

// If a ZooKeeper cluster looses quorum then a session is reconnected as soon
// as the quorum is restored.
func TestNoQuorum(t *testing.T) {
func TestIntegration_NoQuorum(t *testing.T) {
tc, err := StartTestCluster(t, 3, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -189,7 +187,7 @@ func TestNoQuorum(t *testing.T) {
}
}

func TestWaitForClose(t *testing.T) {
func TestIntegration_WaitForClose(t *testing.T) {
ts, err := StartTestCluster(t, 1, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -225,7 +223,7 @@ CONNECTED:
}
}

func TestBadSession(t *testing.T) {
func TestIntegration_BadSession(t *testing.T) {
ts, err := StartTestCluster(t, 1, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"
)

func TestRecurringReAuthHang(t *testing.T) {
func TestIntegration_RecurringReAuthHang(t *testing.T) {
zkC, err := StartTestCluster(t, 3, ioutil.Discard, ioutil.Discard)
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions dnshostprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func localhostLookupHost(host string) ([]string, error) {

// TestDNSHostProviderCreate is just like TestCreate, but with an
// overridden HostProvider that ignores the provided hostname.
func TestDNSHostProviderCreate(t *testing.T) {
func TestIntegration_DNSHostProviderCreate(t *testing.T) {
ts, err := StartTestCluster(t, 1, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -96,7 +96,7 @@ var _ HostProvider = &localHostPortsFacade{}
// restarts. It wraps the DNSHostProvider in a lightweight facade that
// remaps addresses to localhost:$PORT combinations corresponding to
// the test ZooKeeper instances.
func TestDNSHostProviderReconnect(t *testing.T) {
func TestIntegration_DNSHostProviderReconnect(t *testing.T) {
ts, err := StartTestCluster(t, 3, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
t.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"
)

func TestLock(t *testing.T) {
func TestIntegration_Lock(t *testing.T) {
ts, err := StartTestCluster(t, 1, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestLock(t *testing.T) {

// This tests creating a lock with a path that's more than 1 node deep (e.g. "/test-multi-level/lock"),
// when a part of that path already exists (i.e. "/test-multi-level" node already exists).
func TestMultiLevelLock(t *testing.T) {
func TestIntegration_MultiLevelLock(t *testing.T) {
ts, err := StartTestCluster(t, 1, nil, logWriter{t: t, p: "[ZKERR] "})
if err != nil {
t.Fatal(err)
Expand Down
14 changes: 6 additions & 8 deletions server_help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package zk
import (
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand All @@ -17,10 +16,6 @@ const (
_testMyIDFileName = "myid"
)

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

type TestServer struct {
Port int
Path string
Expand All @@ -38,6 +33,8 @@ type TestCluster struct {
// testing. This should be used on CI systems and local only when needed whereas unit tests should remain
// fast and not rely on external dependencies.
func StartTestCluster(t *testing.T, size int, stdout, stderr io.Writer) (*TestCluster, error) {
t.Helper()

if testing.Short() {
t.Skip("ZK cluster tests skipped in short case.")
}
Expand All @@ -52,8 +49,7 @@ func StartTestCluster(t *testing.T, size int, stdout, stderr io.Writer) (*TestCl
}
}

tmpPath, err := ioutil.TempDir("", "gozk")
requireNoError(t, err, "failed to create tmp dir for test server setup")
tmpPath := t.TempDir()

success := false
startPort := int(rand.Int31n(6000) + 10000)
Expand Down Expand Up @@ -150,7 +146,7 @@ func (tc *TestCluster) Stop() error {
for _, srv := range tc.Servers {
srv.Srv.Stop()
}
defer os.RemoveAll(tc.Path)

return tc.waitForStop(5, time.Second)
}

Expand Down Expand Up @@ -252,6 +248,8 @@ func (tc *TestCluster) StopAllServers() error {
}

func requireNoError(t *testing.T, err error, msgAndArgs ...interface{}) {
t.Helper()

if err != nil {
t.Logf("received unexpected error: %v", err)
t.Fatal(msgAndArgs...)
Expand Down
Loading

0 comments on commit e6155c8

Please sign in to comment.