Skip to content

Commit

Permalink
Merge pull request hashicorp#466 from hashicorp/dnephin/update-ci-config
Browse files Browse the repository at this point in the history
ci: update config
  • Loading branch information
dnephin authored May 17, 2021
2 parents cfb599d + f93d7eb commit f7242e7
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 143 deletions.
153 changes: 54 additions & 99 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
version: 2.1

references:
images:
go-1.13: &GOLANG_1_13_IMAGE docker.mirror.hashicorp.services/circleci/golang:1.13
go-1.14: &GOLANG_1_14_IMAGE docker.mirror.hashicorp.services/circleci/golang:1.14
go-1.15: &GOLANG_1_15_IMAGE docker.mirror.hashicorp.services/circleci/golang:1.15
go-1.16: &GOLANG_1_16_IMAGE docker.mirror.hashicorp.services/circleci/golang:1.16
workflows:
ci:
jobs:
- lint
- go-test:
name: test go1.15
version: "1.15"
- go-test:
name: test go1.16
version: "1.16"
- go-test:
name: test go1.16 32bit
version: "1.16"
goarch: "386"
args: "" # remove -race

environment: &ENVIRONMENT
TEST_RESULTS_DIR: &TEST_RESULTS_DIR /tmp/test-results # path to where test results are saved
GOTRACEBACK: "all"
GO111MODULE: "on"
GOMAXPROCS: 2
executors:
golang:
parameters:
version:
type: string
goarch:
type: string
default: amd64
docker:
- image: docker.mirror.hashicorp.services/circleci/golang:<<parameters.version>>
environment:
TEST_RESULTS_DIR: /tmp/test-results
GOTRACEBACK: "all"
GO111MODULE: "on"
GOMAXPROCS: 2
GOARCH: <<parameters.goarch>>

jobs:
go-fmt-and-vet:
docker:
- image: *GOLANG_1_14_IMAGE
lint:
executor:
name: golang
version: "1.16"
steps:
- checkout

# Restore go module cache if there is one
- restore_cache:
keys:
- raft-modcache-v1-{{ checksum "go.mod" }}

- run: go mod download

# Save go module cache if the go.mod file has changed
- save_cache:
key: raft-modcache-v1-{{ checksum "go.mod" }}
paths:
- "/go/pkg/mod"

# check go fmt output because it does not report non-zero when there are fmt changes
- run:
name: check go fmt
Expand All @@ -48,87 +57,33 @@ jobs:
go vet $PACKAGE_NAMES
go-test:
description: Runs go tests
parameters:
go-version:
description: what go version to use
version:
type: string
docker:
- image: << parameters.go-version >>
environment: *ENVIRONMENT
steps:
- checkout
- run: mkdir -p $TEST_RESULTS_DIR

- restore_cache: # restore cache
keys:
- raft-modcache-v1-{{ checksum "go.mod" }}

# run go tests with gotestsum
- run: make ci.integ
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results

go-test-32bit:
description: Runs go tests - 32 bit
parameters:
go-version:
description: what go version to use
goarch:
type: string
docker:
- image: << parameters.go-version >>
environment:
<<: *ENVIRONMENT
GOARCH: "386"
default: amd64
args:
type: string
default: "-race"
executor:
name: golang
version: <<parameters.version>>
goarch: <<parameters.goarch>>
steps:
- run: go env
- checkout
- run: mkdir -p $TEST_RESULTS_DIR
- run:
name: run tests
environment:
INTEG_TESTS: "yes"
GOTESTSUM_FORMAT: short-verbose
command: |
gotestsum --junitfile ${TEST_RESULTS_DIR}/junit.xml -- -timeout=240s <<parameters.args>> .
gotestsum --junitfile ${TEST_RESULTS_DIR}/junit-batch.xml -- -timeout=240s <<parameters.args>> -tags batchtest .
- restore_cache: # restore cache
keys:
- raft-modcache-v1-{{ checksum "go.mod" }}

# run go tests with gotestsum
- run: make ci.test-norace
- store_test_results:
path: /tmp/test-results
- store_artifacts:
path: /tmp/test-results

workflows:
version: 2
test-and-build:
jobs:
- go-fmt-and-vet
- go-test:
name: test go1.13
go-version: *GOLANG_1_13_IMAGE
requires:
- go-fmt-and-vet
- go-test:
name: test go1.14
go-version: *GOLANG_1_14_IMAGE
requires:
- go-fmt-and-vet
- go-test:
name: test go1.15
go-version: *GOLANG_1_15_IMAGE
requires:
- go-fmt-and-vet
- go-test:
name: test go1.16
go-version: *GOLANG_1_16_IMAGE
requires:
- go-fmt-and-vet
- go-test-32bit:
name: test go1.13 - 32bit
go-version: *GOLANG_1_13_IMAGE
requires:
- go-fmt-and-vet
- go-test-32bit:
name: test go1.14 - 32bit
go-version: *GOLANG_1_14_IMAGE
requires:
- go-fmt-and-vet
12 changes: 0 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ integ: test
INTEG_TESTS=yes go test $(TESTARGS) -timeout=60s -run=Integ .
INTEG_TESTS=yes go test $(TESTARGS) -timeout=60s -tags batchtest -run=Integ .

ci.test-norace:
gotestsum --format=short-verbose --junitfile $(TEST_RESULTS_DIR)/gotestsum-report-test.xml -- -timeout=180s
gotestsum --format=short-verbose --junitfile $(TEST_RESULTS_DIR)/gotestsum-report-test.xml -- -timeout=180s -tags batchtest

ci.test:
gotestsum --format=short-verbose --junitfile $(TEST_RESULTS_DIR)/gotestsum-report-test.xml -- -timeout=180s -race .
gotestsum --format=short-verbose --junitfile $(TEST_RESULTS_DIR)/gotestsum-report-test.xml -- -timeout=180s -race -tags batchtest .

ci.integ: ci.test
INTEG_TESTS=yes gotestsum --format=short-verbose --junitfile $(TEST_RESULTS_DIR)/gotestsum-report-integ.xml -- -timeout=60s -run=Integ .
INTEG_TESTS=yes gotestsum --format=short-verbose --junitfile $(TEST_RESULTS_DIR)/gotestsum-report-integ.xml -- -timeout=60s -run=Integ -tags batchtest .

fuzz:
cd ./fuzzy && go test $(TESTARGS) -timeout=20m .
cd ./fuzzy && go test $(TESTARGS) -timeout=20m -tags batchtest .
Expand Down
39 changes: 25 additions & 14 deletions net_transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package raft
import (
"bytes"
"fmt"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/require"
"net"
"reflect"
"strings"
"sync"
"sync/atomic"
"testing"
"time"

"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/require"
)

type testAddrProvider struct {
Expand Down Expand Up @@ -60,7 +61,8 @@ func TestNetworkTransport_CloseStreams(t *testing.T) {
// Verify the command
req := rpc.Command.(*AppendEntriesRequest)
if !reflect.DeepEqual(req, &args) {
t.Fatalf("command mismatch: %#v %#v", *req, args)
t.Errorf("command mismatch: %#v %#v", *req, args)
return
}
rpc.Respond(&resp, nil)

Expand Down Expand Up @@ -220,13 +222,14 @@ func TestNetworkTransport_AppendEntries(t *testing.T) {
// Verify the command
req := rpc.Command.(*AppendEntriesRequest)
if !reflect.DeepEqual(req, &args) {
t.Fatalf("command mismatch: %#v %#v", *req, args)
t.Errorf("command mismatch: %#v %#v", *req, args)
return
}

rpc.Respond(&resp, nil)

case <-time.After(200 * time.Millisecond):
t.Fatalf("timeout")
t.Errorf("timeout")
}
}()

Expand Down Expand Up @@ -290,12 +293,14 @@ func TestNetworkTransport_AppendEntriesPipeline(t *testing.T) {
// Verify the command
req := rpc.Command.(*AppendEntriesRequest)
if !reflect.DeepEqual(req, &args) {
t.Fatalf("command mismatch: %#v %#v", *req, args)
t.Errorf("command mismatch: %#v %#v", *req, args)
return
}
rpc.Respond(&resp, nil)

case <-time.After(200 * time.Millisecond):
t.Fatalf("timeout")
t.Errorf("timeout")
return
}
}
}()
Expand Down Expand Up @@ -376,7 +381,8 @@ func TestNetworkTransport_AppendEntriesPipeline_CloseStreams(t *testing.T) {
// Verify the command
req := rpc.Command.(*AppendEntriesRequest)
if !reflect.DeepEqual(req, &args) {
t.Fatalf("command mismatch: %#v %#v", *req, args)
t.Errorf("command mismatch: %#v %#v", *req, args)
return
}
rpc.Respond(&resp, nil)

Expand Down Expand Up @@ -472,13 +478,15 @@ func TestNetworkTransport_RequestVote(t *testing.T) {
// Verify the command
req := rpc.Command.(*RequestVoteRequest)
if !reflect.DeepEqual(req, &args) {
t.Fatalf("command mismatch: %#v %#v", *req, args)
t.Errorf("command mismatch: %#v %#v", *req, args)
return
}

rpc.Respond(&resp, nil)

case <-time.After(200 * time.Millisecond):
t.Fatalf("timeout")
t.Errorf("timeout")
return
}
}()

Expand Down Expand Up @@ -533,7 +541,8 @@ func TestNetworkTransport_InstallSnapshot(t *testing.T) {
// Verify the command
req := rpc.Command.(*InstallSnapshotRequest)
if !reflect.DeepEqual(req, &args) {
t.Fatalf("command mismatch: %#v %#v", *req, args)
t.Errorf("command mismatch: %#v %#v", *req, args)
return
}

// Try to read the bytes
Expand All @@ -542,13 +551,14 @@ func TestNetworkTransport_InstallSnapshot(t *testing.T) {

// Compare
if bytes.Compare(buf, []byte("0123456789")) != 0 {
t.Fatalf("bad buf %v", buf)
t.Errorf("bad buf %v", buf)
return
}

rpc.Respond(&resp, nil)

case <-time.After(200 * time.Millisecond):
t.Fatalf("timeout")
t.Errorf("timeout")
}
}()

Expand Down Expand Up @@ -647,7 +657,8 @@ func TestNetworkTransport_PooledConn(t *testing.T) {
// Verify the command
req := rpc.Command.(*AppendEntriesRequest)
if !reflect.DeepEqual(req, &args) {
t.Fatalf("command mismatch: %#v %#v", *req, args)
t.Errorf("command mismatch: %#v %#v", *req, args)
return
}
rpc.Respond(&resp, nil)

Expand Down
22 changes: 13 additions & 9 deletions raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,12 @@ func TestRaft_RecoverCluster_NoState(t *testing.T) {
}

func TestRaft_RecoverCluster(t *testing.T) {
// Run with different number of applies which will cover no snapshot and
// snapshot + log scenarios. By sweeping through the trailing logs value
// we will also hit the case where we have a snapshot only.
var err error
snapshotThreshold := 5
runRecover := func(t *testing.T, applies int) {
var err error
conf := inmemConfig(t)
conf.TrailingLogs = 10
conf.SnapshotThreshold = uint64(snapshotThreshold)
c := MakeCluster(3, t, conf)
defer c.Close()

Expand Down Expand Up @@ -212,11 +211,16 @@ func TestRaft_RecoverCluster(t *testing.T) {
c.EnsureSame(t)
c.EnsureSamePeers(t)
}
for applies := 0; applies < 10; applies++ {
t.Run(fmt.Sprintf("%d applies", applies), func(t *testing.T) {
runRecover(t, applies)
})
}

t.Run("no snapshot, no trailing logs", func(t *testing.T) {
runRecover(t, 0)
})
t.Run("no snapshot, some trailing logs", func(t *testing.T) {
runRecover(t, snapshotThreshold-1)
})
t.Run("snapshot, with trailing logs", func(t *testing.T) {
runRecover(t, snapshotThreshold+20)
})
}

func TestRaft_HasExistingState(t *testing.T) {
Expand Down
Loading

0 comments on commit f7242e7

Please sign in to comment.