diff --git a/file_snapshot.go b/file_snapshot.go index 8e601399..ae8aad3c 100644 --- a/file_snapshot.go +++ b/file_snapshot.go @@ -11,7 +11,6 @@ import ( "hash" "hash/crc64" "io" - "io/ioutil" "os" "path/filepath" "runtime" @@ -245,7 +244,7 @@ func (f *FileSnapshotStore) List() ([]*SnapshotMeta, error) { // getSnapshots returns all the known snapshots. func (f *FileSnapshotStore) getSnapshots() ([]*fileSnapshotMeta, error) { // Get the eligible snapshots - snapshots, err := ioutil.ReadDir(f.path) + snapshots, err := os.ReadDir(f.path) if err != nil { f.logger.Error("failed to scan snapshot directory", "error", err) return nil, err diff --git a/file_snapshot_test.go b/file_snapshot_test.go index 9b360850..30b9ee09 100644 --- a/file_snapshot_test.go +++ b/file_snapshot_test.go @@ -6,7 +6,6 @@ package raft import ( "bytes" "io" - "io/ioutil" "os" "reflect" "runtime" @@ -28,13 +27,13 @@ func TestFileSnapshotSinkImpl(t *testing.T) { } func TestFileSS_CreateSnapshotMissingParentDir(t *testing.T) { - parent, err := ioutil.TempDir("", "raft") + parent, err := os.MkdirTemp("", "raft") if err != nil { t.Fatalf("err: %v ", err) } defer os.RemoveAll(parent) - dir, err := ioutil.TempDir(parent, "raft") + dir, err := os.MkdirTemp(parent, "raft") if err != nil { t.Fatalf("err: %v ", err) } @@ -54,7 +53,7 @@ func TestFileSS_CreateSnapshotMissingParentDir(t *testing.T) { } func TestFileSS_CreateSnapshot(t *testing.T) { // Create a test dir - dir, err := ioutil.TempDir("", "raft") + dir, err := os.MkdirTemp("", "raft") if err != nil { t.Fatalf("err: %v ", err) } @@ -162,7 +161,7 @@ func TestFileSS_CreateSnapshot(t *testing.T) { func TestFileSS_CancelSnapshot(t *testing.T) { // Create a test dir - dir, err := ioutil.TempDir("", "raft") + dir, err := os.MkdirTemp("", "raft") if err != nil { t.Fatalf("err: %v ", err) } @@ -200,7 +199,7 @@ func TestFileSS_Retention(t *testing.T) { var err error // Create a test dir var dir string - dir, err = ioutil.TempDir("", "raft") + dir, err = os.MkdirTemp("", "raft") if err != nil { t.Fatalf("err: %v ", err) } @@ -253,7 +252,7 @@ func TestFileSS_BadPerm(t *testing.T) { // Create a temp dir var dir1 string - dir1, err = ioutil.TempDir("", "raft") + dir1, err = os.MkdirTemp("", "raft") if err != nil { t.Fatalf("err: %s", err) } @@ -261,7 +260,7 @@ func TestFileSS_BadPerm(t *testing.T) { // Create a sub dir and remove all permissions var dir2 string - dir2, err = ioutil.TempDir(dir1, "badperm") + dir2, err = os.MkdirTemp(dir1, "badperm") if err != nil { t.Fatalf("err: %s", err) } @@ -277,13 +276,13 @@ func TestFileSS_BadPerm(t *testing.T) { } func TestFileSS_MissingParentDir(t *testing.T) { - parent, err := ioutil.TempDir("", "raft") + parent, err := os.MkdirTemp("", "raft") if err != nil { t.Fatalf("err: %v ", err) } defer os.RemoveAll(parent) - dir, err := ioutil.TempDir(parent, "raft") + dir, err := os.MkdirTemp(parent, "raft") if err != nil { t.Fatalf("err: %v ", err) } @@ -297,7 +296,7 @@ func TestFileSS_MissingParentDir(t *testing.T) { func TestFileSS_Ordering(t *testing.T) { // Create a test dir - dir, err := ioutil.TempDir("", "raft") + dir, err := os.MkdirTemp("", "raft") if err != nil { t.Fatalf("err: %v ", err) } diff --git a/fuzzy/cluster.go b/fuzzy/cluster.go index 59a84891..0dde3804 100644 --- a/fuzzy/cluster.go +++ b/fuzzy/cluster.go @@ -7,7 +7,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "path/filepath" "testing" @@ -294,7 +293,7 @@ func (c *cluster) VerifyFSM(t *testing.T) { } func (c *cluster) RecordState(t *testing.T) { - td, _ := ioutil.TempDir(os.Getenv("TEST_FAIL_DIR"), "failure") + td, _ := os.MkdirTemp(os.Getenv("TEST_FAIL_DIR"), "failure") sd, _ := resolveDirectory("data", false) copyDir(td, sd) dump := func(n *raftNode) { diff --git a/fuzzy/go.sum b/fuzzy/go.sum index 8b879834..787f47d6 100644 --- a/fuzzy/go.sum +++ b/fuzzy/go.sum @@ -9,20 +9,14 @@ github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-hclog v0.9.1 h1:9PZfAcVEvez4yhLH2TBU64/h/z4xlFI80cWXRrxuKuM= github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/hashicorp/go-hclog v0.16.0 h1:uCeOEwSWGMwhJUdpUjk+1cVKIEfGu2/1nFXukimi2MU= -github.com/hashicorp/go-hclog v0.16.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.5 h1:i9R9JSrqIz0QVLz3sz+i3YJdT7TTSLcfLLzJi9aZTuI= github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= -github.com/hashicorp/go-msgpack v1.1.5 h1:9byZdVjKTe5mce63pRVNP1L7UAmdHOTEMGehn6KvJWs= -github.com/hashicorp/go-msgpack v1.1.5/go.mod h1:gWVc3sv/wbDmR3rQsj1CAktEZzoz1YNK9NfGLXJ69/4= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -30,13 +24,6 @@ github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCO github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea h1:xykPFhrBAS2J0VBzVa5e80b5ZtYuNQtgXjN40qBZlD4= github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea/go.mod h1:pNv7Wc3ycL6F5oOWn+tPGo2gWD4a5X+yp/ntwdKLjRk= -github.com/hashicorp/raft-boltdb v0.0.0-20210409134258-03c10cc3d4ea h1:RxcPJuutPRM8PUOyiweMmkuNO+RJyfy2jds2gfvgNmU= -github.com/hashicorp/raft-boltdb v0.0.0-20210409134258-03c10cc3d4ea/go.mod h1:qRd6nFJYYS6Iqnc/8HcUmko2/2Gw8qTFEmxDLii6W5I= -github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10= -github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= @@ -52,17 +39,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191008105621-543471e840be h1:QAcqgptGM8IQBC9K/RC4o+O9YmqEm0diQn9QmZw/0mU= -golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 h1:g9s1Ppvvun/fI+BptTMj909BBIcGrzQ32k9FNlcevOE= golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190424220101-1e8e1cfdf96b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= diff --git a/inmem_snapshot.go b/inmem_snapshot.go index 30ede87a..d23bc209 100644 --- a/inmem_snapshot.go +++ b/inmem_snapshot.go @@ -7,7 +7,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "sync" ) @@ -88,7 +87,7 @@ func (m *InmemSnapshotStore) Open(id string) (*SnapshotMeta, io.ReadCloser, erro // Make a copy of the contents, since a bytes.Buffer can only be read // once. contents := bytes.NewBuffer(m.latest.contents.Bytes()) - return &m.latest.meta, ioutil.NopCloser(contents), nil + return &m.latest.meta, io.NopCloser(contents), nil } // Write appends the given bytes to the snapshot contents diff --git a/integ_test.go b/integ_test.go index 22d522a0..90566349 100644 --- a/integ_test.go +++ b/integ_test.go @@ -6,7 +6,6 @@ package raft import ( "bytes" "fmt" - "io/ioutil" "os" "sync/atomic" "testing" @@ -77,7 +76,7 @@ func MakeRaft(t *testing.T, conf *Config, bootstrap bool) *RaftEnv { conf = inmemConfig(t) } - dir, err := ioutil.TempDir("", "raft") + dir, err := os.MkdirTemp("", "raft") if err != nil { t.Fatalf("err: %v ", err) } diff --git a/net_transport.go b/net_transport.go index ae4a3f79..a780510b 100644 --- a/net_transport.go +++ b/net_transport.go @@ -232,7 +232,7 @@ func (n *NetworkTransport) getStreamContext() context.Context { return n.streamCtx } -// SetHeartbeatHandler is used to setup a heartbeat handler +// SetHeartbeatHandler is used to set up a heartbeat handler // as a fast-pass. This is to avoid head-of-line blocking from // disk IO. func (n *NetworkTransport) SetHeartbeatHandler(cb func(rpc RPC)) { @@ -367,7 +367,7 @@ func (n *NetworkTransport) returnConn(conn *netConn) { defer n.connPoolLock.Unlock() key := conn.target - conns, _ := n.connPool[key] + conns := n.connPool[key] if !n.IsShutdown() && len(conns) < n.maxPool { n.connPool[key] = append(conns, conn) @@ -793,7 +793,7 @@ func (n *netPipeline) Consumer() <-chan AppendFuture { return n.doneCh } -// Closed is used to shutdown the pipeline connection. +// Close is used to shut down the pipeline connection. func (n *netPipeline) Close() error { n.shutdownLock.Lock() defer n.shutdownLock.Unlock() diff --git a/peersjson.go b/peersjson.go index af6027a5..d81d5ec4 100644 --- a/peersjson.go +++ b/peersjson.go @@ -6,7 +6,7 @@ package raft import ( "bytes" "encoding/json" - "io/ioutil" + "os" ) // ReadPeersJSON consumes a legacy peers.json file in the format of the old JSON @@ -17,7 +17,7 @@ import ( // support for these, nor non-voter suffrage types. func ReadPeersJSON(path string) (Configuration, error) { // Read in the file. - buf, err := ioutil.ReadFile(path) + buf, err := os.ReadFile(path) if err != nil { return Configuration{}, err } @@ -66,7 +66,7 @@ type configEntry struct { // versions that use server IDs. func ReadConfigJSON(path string) (Configuration, error) { // Read in the file. - buf, err := ioutil.ReadFile(path) + buf, err := os.ReadFile(path) if err != nil { return Configuration{}, err } diff --git a/peersjson_test.go b/peersjson_test.go index 53001749..4dd1c1b4 100644 --- a/peersjson_test.go +++ b/peersjson_test.go @@ -4,7 +4,6 @@ package raft import ( - "io/ioutil" "os" "path/filepath" "reflect" @@ -15,14 +14,14 @@ import ( func TestPeersJSON_BadConfiguration(t *testing.T) { var err error var base string - base, err = ioutil.TempDir("", "") + base, err = os.MkdirTemp("", "") if err != nil { t.Fatalf("err: %v", err) } defer os.RemoveAll(base) peers := filepath.Join(base, "peers.json") - if err = ioutil.WriteFile(peers, []byte("null"), 0666); err != nil { + if err = os.WriteFile(peers, []byte("null"), 0666); err != nil { t.Fatalf("err: %v", err) } @@ -35,7 +34,7 @@ func TestPeersJSON_BadConfiguration(t *testing.T) { func TestPeersJSON_ReadPeersJSON(t *testing.T) { var err error var base string - base, err = ioutil.TempDir("", "") + base, err = os.MkdirTemp("", "") if err != nil { t.Fatalf("err: %v", err) } @@ -47,7 +46,7 @@ func TestPeersJSON_ReadPeersJSON(t *testing.T) { "127.0.0.3:123"] `) peers := filepath.Join(base, "peers.json") - if err = ioutil.WriteFile(peers, content, 0666); err != nil { + if err = os.WriteFile(peers, content, 0666); err != nil { t.Fatalf("err: %v", err) } var configuration Configuration @@ -83,7 +82,7 @@ func TestPeersJSON_ReadPeersJSON(t *testing.T) { func TestPeersJSON_ReadConfigJSON(t *testing.T) { var err error var base string - base, err = ioutil.TempDir("", "") + base, err = os.MkdirTemp("", "") if err != nil { t.Fatalf("err: %v", err) } @@ -108,7 +107,7 @@ func TestPeersJSON_ReadConfigJSON(t *testing.T) { ] `) peers := filepath.Join(base, "peers.json") - if err = ioutil.WriteFile(peers, content, 0666); err != nil { + if err = os.WriteFile(peers, content, 0666); err != nil { t.Fatalf("err: %v", err) } diff --git a/raft.go b/raft.go index 8594f442..be674344 100644 --- a/raft.go +++ b/raft.go @@ -8,7 +8,6 @@ import ( "container/list" "fmt" "io" - "io/ioutil" "sync/atomic" "time" @@ -217,7 +216,7 @@ func (r *Raft) runFollower() { // Check if we have had a successful contact lastContact := r.LastContact() - if time.Now().Sub(lastContact) < hbTimeout { + if time.Since(lastContact) < hbTimeout { continue } @@ -1511,7 +1510,6 @@ func (r *Raft) appendEntries(rpc RPC, a *AppendEntriesRequest) { // Everything went well, set success resp.Success = true r.setLastContact() - return } // processConfigurationLogEntry takes a log entry and updates the latest @@ -1631,7 +1629,7 @@ func (r *Raft) requestVote(rpc RPC, req *RequestVoteRequest) { // Check if we've voted in this election before if lastVoteTerm == req.Term && lastVoteCandBytes != nil { r.logger.Info("duplicate requestVote for same term", "term", req.Term) - if bytes.Compare(lastVoteCandBytes, candidateBytes) == 0 { + if bytes.Equal(lastVoteCandBytes, candidateBytes) { r.logger.Warn("duplicate requestVote from", "candidate", candidate) resp.Granted = true } @@ -1664,7 +1662,6 @@ func (r *Raft) requestVote(rpc RPC, req *RequestVoteRequest) { resp.Granted = true r.setLastContact() - return } // installSnapshot is invoked when we get a InstallSnapshot RPC call. @@ -1680,7 +1677,7 @@ func (r *Raft) installSnapshot(rpc RPC, req *InstallSnapshotRequest) { } var rpcErr error defer func() { - io.Copy(ioutil.Discard, rpc.Reader) // ensure we always consume all the snapshot data from the stream [see issue #212] + _, _ = io.Copy(io.Discard, rpc.Reader) // ensure we always consume all the snapshot data from the stream [see issue #212] rpc.Respond(resp, rpcErr) }() diff --git a/raft_test.go b/raft_test.go index d941c5a2..d8fb4168 100644 --- a/raft_test.go +++ b/raft_test.go @@ -8,8 +8,6 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" - "log" "os" "path/filepath" "reflect" @@ -428,12 +426,9 @@ func TestRaft_LeaderFail(t *testing.T) { if len(fsm.logs) != 2 { t.Fatalf("did not apply both to FSM! %v", fsm.logs) } - if bytes.Compare(fsm.logs[0], []byte("test")) != 0 { - t.Fatalf("first entry should be 'test'") - } - if bytes.Compare(fsm.logs[1], []byte("apply")) != 0 { - t.Fatalf("second entry should be 'apply'") - } + + require.Equal(t, fsm.logs[0], []byte("test")) + require.Equal(t, fsm.logs[1], []byte("apply")) fsm.Unlock() } } @@ -1309,13 +1304,13 @@ func TestRaft_SnapshotRestore_PeerChange(t *testing.T) { content := []byte(fmt.Sprintf("[%s]", strings.Join(peers, ","))) // Perform a manual recovery on the cluster. - base, err := ioutil.TempDir("", "") + base, err := os.MkdirTemp("", "") if err != nil { t.Fatalf("err: %v", err) } defer os.RemoveAll(base) peersFile := filepath.Join(base, "peers.json") - if err = ioutil.WriteFile(peersFile, content, 0666); err != nil { + if err = os.WriteFile(peersFile, content, 0666); err != nil { t.Fatalf("[ERR] err: %v", err) } configuration, err := ReadPeersJSON(peersFile) @@ -1549,9 +1544,7 @@ func snapshotAndRestore(t *testing.T, offset uint64, monotonicLogStore bool, res } for i, entry := range fsm.logs { expected := []byte(fmt.Sprintf("test %d", i)) - if !bytes.Equal(entry, expected) { - t.Fatalf("Log entry bad: %v", entry) - } + require.Equal(t, entry, expected) } fsm.Unlock() @@ -2921,8 +2914,8 @@ func TestRaft_FollowerRemovalNoElection(t *testing.T) { c := MakeCluster(3, t, inmemConf) defer c.Close() - waitForLeader(c) - + err := waitForLeader(c) + require.NoError(t, err) leader := c.Leader() // Wait until we have 2 followers @@ -2975,8 +2968,8 @@ func TestRaft_VoteWithNoIDNoAddr(t *testing.T) { c := MakeCluster(3, t, nil) defer c.Close() - waitForLeader(c) - + err := waitForLeader(c) + require.NoError(t, err) leader := c.Leader() // Wait until we have 2 followers @@ -3045,25 +3038,6 @@ func waitForLeader(c *cluster) error { return errors.New("no leader elected") } -func waitForNewLeader(c *cluster, id ServerID) error { - count := 0 - for count < 100 { - r := c.GetInState(Leader) - if len(r) >= 1 && r[0].localID != id { - return nil - } else { - if len(r) == 0 { - log.Println("no leader yet") - } else { - log.Printf("leader still %s\n", id) - } - } - count++ - time.Sleep(100 * time.Millisecond) - } - return errors.New("no leader elected") -} - func TestRaft_runFollower_State_Transition(t *testing.T) { type fields struct { conf *Config diff --git a/testing.go b/testing.go index 3eb0ac59..96961b60 100644 --- a/testing.go +++ b/testing.go @@ -8,7 +8,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "reflect" "sync" @@ -745,7 +744,7 @@ func makeCluster(t *testing.T, opts *MakeClusterOpts) *cluster { // Setup the stores and transports for i := 0; i < opts.Peers; i++ { - dir, err := ioutil.TempDir("", "raft") + dir, err := os.MkdirTemp("", "raft") if err != nil { t.Fatalf("err: %v", err) } @@ -851,7 +850,7 @@ func MakeClusterCustom(t *testing.T, opts *MakeClusterOpts) *cluster { // NOTE: This is exposed for middleware testing purposes and is not a stable API func FileSnapTest(t *testing.T) (string, *FileSnapshotStore) { // Create a test dir - dir, err := ioutil.TempDir("", "raft") + dir, err := os.MkdirTemp("", "raft") if err != nil { t.Fatalf("err: %v ", err) }