Skip to content

Commit

Permalink
gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
mpalmi committed Jul 3, 2023
1 parent 780339e commit 672daee
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 44 deletions.
1 change: 0 additions & 1 deletion commitment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ func TestCommitment_noVoterSanity(t *testing.T) {
if drainNotifyCh(commitCh) {
t.Fatalf("unexpected commit notify")
}

}

// Single voter commits immediately.
Expand Down
4 changes: 2 additions & 2 deletions file_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func NewFileSnapshotStoreWithLogger(base string, retain int, logger hclog.Logger

// Ensure our path exists
path := filepath.Join(base, snapPath)
if err := os.MkdirAll(path, 0755); err != nil && !os.IsExist(err) {
if err := os.MkdirAll(path, 0o755); err != nil && !os.IsExist(err) {
return nil, fmt.Errorf("snapshot path not accessible: %v", err)
}

Expand Down Expand Up @@ -170,7 +170,7 @@ func (f *FileSnapshotStore) Create(version SnapshotVersion, index, term uint64,
f.logger.Info("creating new snapshot", "path", path)

// Make the directory
if err := os.MkdirAll(path, 0755); err != nil {
if err := os.MkdirAll(path, 0o755); err != nil {
f.logger.Error("failed to make snapshot directly", "error", err)
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions file_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func TestFileSS_CreateSnapshotMissingParentDir(t *testing.T) {
if err != nil {
t.Fatalf("should not fail when using non existing parent")
}

}

func TestFileSS_CreateSnapshot(t *testing.T) {
// Create a test dir
dir, err := os.MkdirTemp("", "raft")
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestFileSS_BadPerm(t *testing.T) {
if err != nil {
t.Fatalf("err: %s", err)
}
if err = os.Chmod(dir2, 000); err != nil {
if err = os.Chmod(dir2, 0o00); err != nil {
t.Fatalf("err: %s", err)
}
defer os.Chmod(dir2, 777) // Set perms back for delete
Expand Down
4 changes: 2 additions & 2 deletions fuzzy/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (c *cluster) RecordState(t *testing.T) {
copyDir(td, sd)
dump := func(n *raftNode) {
nt := filepath.Join(td, n.name)
os.Mkdir(nt, 0777)
os.Mkdir(nt, 0o777)
n.fsm.WriteTo(filepath.Join(nt, "fsm.txt"))
n.transport.DumpLog(nt)
}
Expand All @@ -315,7 +315,7 @@ func copyDir(target, src string) {
filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
relPath := path[len(src):]
if info.IsDir() {
return os.MkdirAll(filepath.Join(target, relPath), 0777)
return os.MkdirAll(filepath.Join(target, relPath), 0o777)
}
return copyFile(filepath.Join(target, relPath), path)
})
Expand Down
1 change: 1 addition & 0 deletions fuzzy/fsm_batch.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:build batchtest
// +build batchtest

package fuzzy
Expand Down
2 changes: 1 addition & 1 deletion fuzzy/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func resolveDirectory(dir string, create bool) (string, error) {
}
if create {
if _, err := os.Stat(resolved); os.IsNotExist(err) {
if err := os.MkdirAll(resolved, 0744); err != nil {
if err := os.MkdirAll(resolved, 0o744); err != nil {
return "", err
}
}
Expand Down
7 changes: 3 additions & 4 deletions fuzzy/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ import (
"bytes"
"errors"
"fmt"
"github.com/hashicorp/go-hclog"
"io"
"os"
"path/filepath"
"sync"
"time"

"github.com/hashicorp/go-hclog"

"github.com/hashicorp/go-msgpack/codec"
"github.com/hashicorp/raft"
)

var (
codecHandle codec.MsgpackHandle
)
var codecHandle codec.MsgpackHandle

type appendEntries struct {
source string
Expand Down
3 changes: 2 additions & 1 deletion inmem_transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
package raft

import (
"github.com/stretchr/testify/require"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestInmemTransportImpl(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func TestRaft_RestartFollower_LongInitialHeartbeat(t *testing.T) {
seeNewLeader := func(o *Observation) bool { _, ok := o.Data.(LeaderObservation); return ok }
leaderCh := make(chan Observation)
// TODO Closing this channel results in panics, even though we're calling Release.
//defer close(leaderCh)
// defer close(leaderCh)
leaderChanges := new(uint32)
go func() {
for range leaderCh {
Expand Down
12 changes: 6 additions & 6 deletions log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ func TestOldestLog(t *testing.T) {
{
Name: "simple case",
Logs: []*Log{
&Log{
{
Index: 1234,
Term: 1,
},
&Log{
{
Index: 1235,
Term: 1,
},
&Log{
{
Index: 1236,
Term: 2,
},
Expand Down Expand Up @@ -76,16 +76,16 @@ func TestEmitsLogStoreMetrics(t *testing.T) {

s := NewInmemStore()
logs := []*Log{
&Log{
{
Index: 1234,
Term: 1,
AppendedAt: time.Now(),
},
&Log{
{
Index: 1235,
Term: 1,
},
&Log{
{
Index: 1236,
Term: 2,
},
Expand Down
5 changes: 0 additions & 5 deletions net_transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ func makeAppendRPCResponse() AppendEntriesResponse {
}

func TestNetworkTransport_AppendEntries(t *testing.T) {

for _, useAddrProvider := range []bool{true, false} {
// Transport 1 is consumer
trans1, err := makeTransport(t, useAddrProvider, "localhost:0")
Expand Down Expand Up @@ -279,7 +278,6 @@ func TestNetworkTransport_AppendEntries(t *testing.T) {
}

func TestNetworkTransport_AppendEntriesPipeline(t *testing.T) {

for _, useAddrProvider := range []bool{true, false} {
// Transport 1 is consumer
trans1, err := makeTransport(t, useAddrProvider, "localhost:0")
Expand Down Expand Up @@ -539,7 +537,6 @@ func TestNetworkTransport_AppendEntriesPipeline_MaxRPCsInFlight(t *testing.T) {
}

func TestNetworkTransport_RequestVote(t *testing.T) {

for _, useAddrProvider := range []bool{true, false} {
// Transport 1 is consumer
trans1, err := makeTransport(t, useAddrProvider, "localhost:0")
Expand Down Expand Up @@ -601,7 +598,6 @@ func TestNetworkTransport_RequestVote(t *testing.T) {
}

func TestNetworkTransport_InstallSnapshot(t *testing.T) {

for _, useAddrProvider := range []bool{true, false} {
// Transport 1 is consumer
trans1, err := makeTransport(t, useAddrProvider, "localhost:0")
Expand Down Expand Up @@ -865,7 +861,6 @@ func (sl testCountingStreamLayer) Dial(address ServerAddress, timeout time.Durat
// do not result in a tight loop and spam the log. We verify this here by counting the number
// of calls against Accept() and the logger
func TestNetworkTransport_ListenBackoff(t *testing.T) {

// testTime is the amount of time we will allow NetworkTransport#listen() to run
// This needs to be long enough that to verify that maxDelay is in force,
// but not so long as to be obnoxious when running the test suite.
Expand Down
6 changes: 3 additions & 3 deletions peersjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestPeersJSON_BadConfiguration(t *testing.T) {
defer os.RemoveAll(base)

peers := filepath.Join(base, "peers.json")
if err = os.WriteFile(peers, []byte("null"), 0666); err != nil {
if err = os.WriteFile(peers, []byte("null"), 0o666); err != nil {
t.Fatalf("err: %v", err)
}

Expand All @@ -46,7 +46,7 @@ func TestPeersJSON_ReadPeersJSON(t *testing.T) {
"127.0.0.3:123"]
`)
peers := filepath.Join(base, "peers.json")
if err = os.WriteFile(peers, content, 0666); err != nil {
if err = os.WriteFile(peers, content, 0o666); err != nil {
t.Fatalf("err: %v", err)
}
var configuration Configuration
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestPeersJSON_ReadConfigJSON(t *testing.T) {
]
`)
peers := filepath.Join(base, "peers.json")
if err = os.WriteFile(peers, content, 0666); err != nil {
if err = os.WriteFile(peers, content, 0o666); err != nil {
t.Fatalf("err: %v", err)
}

Expand Down
4 changes: 1 addition & 3 deletions raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ func (r *Raft) leaderLoop() {

start := time.Now()
var groupReady []*list.Element
var groupFutures = make(map[uint64]*logFuture)
groupFutures := make(map[uint64]*logFuture)
var lastIdxInGroup uint64

// Pull all inflight logs that are committed off the queue.
Expand Down Expand Up @@ -784,7 +784,6 @@ func (r *Raft) leaderLoop() {
if v.quorumSize == 0 {
// Just dispatched, start the verification
r.verifyLeader(v)

} else if v.votes < v.quorumSize {
// Early return, means there must be a new leader
r.logger.Warn("new leader elected, stepping down")
Expand Down Expand Up @@ -1411,7 +1410,6 @@ func (r *Raft) appendEntries(rpc RPC, a *AppendEntriesRequest) {
var prevLogTerm uint64
if a.PrevLogEntry == lastIdx {
prevLogTerm = lastTerm

} else {
var prevLog Log
if err := r.logs.GetLog(a.PrevLogEntry, &prevLog); err != nil {
Expand Down
14 changes: 6 additions & 8 deletions raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func TestRaft_AfterShutdown(t *testing.T) {
if f := raft.Shutdown(); f.Error() != nil {
t.Fatalf("shutdown should be idempotent")
}

}

func TestRaft_LiveBootstrap(t *testing.T) {
Expand Down Expand Up @@ -685,7 +684,6 @@ func TestRaft_JoinNode_ConfigStore(t *testing.T) {
t.Fatalf("unexpected number of servers in config change: %v", fsm.configurations[2].Servers)
}
}

}

func TestRaft_RemoveFollower(t *testing.T) {
Expand Down Expand Up @@ -1323,7 +1321,7 @@ func TestRaft_SnapshotRestore_PeerChange(t *testing.T) {
}
defer os.RemoveAll(base)
peersFile := filepath.Join(base, "peers.json")
if err = os.WriteFile(peersFile, content, 0666); err != nil {
if err = os.WriteFile(peersFile, content, 0o666); err != nil {
t.Fatalf("[ERR] err: %v", err)
}
configuration, err := ReadPeersJSON(peersFile)
Expand Down Expand Up @@ -2857,10 +2855,10 @@ func TestRaft_ClusterCanRegainStability_WhenNonVoterWithHigherTermJoin(t *testin
t.Fatalf("err: %v", err)
}

//set that follower term to higher term to faster simulate a partitioning
// set that follower term to higher term to faster simulate a partitioning
newTerm := leader.getCurrentTerm() + 20
followerRemoved.setCurrentTerm(newTerm)
//Add the node back as NonVoter
// Add the node back as NonVoter
future = leader.AddNonvoter(followerRemoved.localID, followerRemoved.localAddr, 0, 0)
if err := future.Error(); err != nil {
t.Fatalf("err: %v", err)
Expand All @@ -2882,7 +2880,7 @@ func TestRaft_ClusterCanRegainStability_WhenNonVoterWithHigherTermJoin(t *testin
t.Fatalf("Should not be leader %s", followerRemoved.localID)
}

//Write some logs to ensure they replicate
// Write some logs to ensure they replicate
for i := 0; i < 100; i++ {
future := leader.Apply([]byte(fmt.Sprintf("test%d", i)), 0)
if err := future.Error(); err != nil {
Expand All @@ -2891,7 +2889,7 @@ func TestRaft_ClusterCanRegainStability_WhenNonVoterWithHigherTermJoin(t *testin
}
c.WaitForReplication(100)

//Remove the server and add it back as Voter
// Remove the server and add it back as Voter
future = leader.RemoveServer(followerRemoved.localID, 0, 0)
if err := future.Error(); err != nil {
t.Fatalf("err: %v", err)
Expand All @@ -2901,7 +2899,7 @@ func TestRaft_ClusterCanRegainStability_WhenNonVoterWithHigherTermJoin(t *testin
// Wait a while
time.Sleep(c.propagateTimeout * 10)

//Write some logs to ensure they replicate
// Write some logs to ensure they replicate
for i := 100; i < 200; i++ {
future := leader.Apply([]byte(fmt.Sprintf("test%d", i)), 0)
if err := future.Error(); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion tcp_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ package raft

import (
"errors"
"github.com/hashicorp/go-hclog"
"io"
"net"
"time"

"github.com/hashicorp/go-hclog"
)

var (
Expand Down
6 changes: 2 additions & 4 deletions testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import (
"github.com/hashicorp/go-msgpack/codec"
)

var (
userSnapshotErrorsOnNoData = true
)
var userSnapshotErrorsOnNoData = true

// Return configurations optimized for in-memory
func inmemConfig(t *testing.T) *Config {
Expand Down Expand Up @@ -433,7 +431,7 @@ func (c *cluster) GetInState(s RaftState) []*Raft {
// Wait until we have a stable instate slice. Each time we see an
// observation a state has changed, recheck it and if it has changed,
// restart the timer.
var pollStartTime = time.Now()
pollStartTime := time.Now()
for {
inState, highestTerm := c.pollState(s)
inStateTime := time.Now()
Expand Down

0 comments on commit 672daee

Please sign in to comment.