use nolint label instead of commenting

This commit is contained in:
Anton Kaliaev 2019-02-06 18:20:10 +04:00
parent 23314daee4
commit 6941d1bb35
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
6 changed files with 217 additions and 237 deletions

View File

@ -364,22 +364,23 @@ func (pool *BlockPool) sendError(err error, peerID p2p.ID) {
} }
// for debugging purposes // for debugging purposes
// func (pool *BlockPool) debug() string { //nolint:unused
// pool.mtx.Lock() func (pool *BlockPool) debug() string {
// defer pool.mtx.Unlock() pool.mtx.Lock()
defer pool.mtx.Unlock()
// str := "" str := ""
// nextHeight := pool.height + pool.requestersLen() nextHeight := pool.height + pool.requestersLen()
// for h := pool.height; h < nextHeight; h++ { for h := pool.height; h < nextHeight; h++ {
// if pool.requesters[h] == nil { if pool.requesters[h] == nil {
// str += fmt.Sprintf("H(%v):X ", h) str += fmt.Sprintf("H(%v):X ", h)
// } else { } else {
// str += fmt.Sprintf("H(%v):", h) str += fmt.Sprintf("H(%v):", h)
// str += fmt.Sprintf("B?(%v) ", pool.requesters[h].block != nil) str += fmt.Sprintf("B?(%v) ", pool.requesters[h].block != nil)
// } }
// } }
// return str return str
// } }
//------------------------------------- //-------------------------------------

View File

@ -378,36 +378,6 @@ func ensureNewEvent(
} }
} }
// func ensureNewRoundStep(stepCh <-chan interface{}, height int64, round int) {
// ensureNewEvent(
// stepCh,
// height,
// round,
// ensureTimeout,
// "Timeout expired while waiting for NewStep event")
// }
// func ensureNewVote(voteCh <-chan interface{}, height int64, round int) {
// select {
// case <-time.After(ensureTimeout):
// break
// case v := <-voteCh:
// edv, ok := v.(types.EventDataVote)
// if !ok {
// panic(fmt.Sprintf("expected a *types.Vote, "+
// "got %v. wrong subscription channel?",
// reflect.TypeOf(v)))
// }
// vote := edv.Vote
// if vote.Height != height {
// panic(fmt.Sprintf("expected height %v, got %v", height, vote.Height))
// }
// if vote.Round != round {
// panic(fmt.Sprintf("expected round %v, got %v", round, vote.Round))
// }
// }
// }
func ensureNewRound(roundCh <-chan interface{}, height int64, round int) { func ensureNewRound(roundCh <-chan interface{}, height int64, round int) {
select { select {
case <-time.After(ensureTimeout): case <-time.After(ensureTimeout):

View File

@ -26,17 +26,18 @@ func NewDominoOp(key, input, output string) DominoOp {
} }
} }
// func DominoOpDecoder(pop ProofOp) (ProofOperator, error) { //nolint:unused
// if pop.Type != ProofOpDomino { func DominoOpDecoder(pop ProofOp) (ProofOperator, error) {
// panic("unexpected proof op type") if pop.Type != ProofOpDomino {
// } panic("unexpected proof op type")
// var op DominoOp // a bit strange as we'll discard this, but it works. }
// err := amino.UnmarshalBinaryLengthPrefixed(pop.Data, &op) var op DominoOp // a bit strange as we'll discard this, but it works.
// if err != nil { err := amino.UnmarshalBinaryLengthPrefixed(pop.Data, &op)
// return nil, cmn.ErrorWrap(err, "decoding ProofOp.Data into SimpleValueOp") if err != nil {
// } return nil, cmn.ErrorWrap(err, "decoding ProofOp.Data into SimpleValueOp")
// return NewDominoOp(string(pop.Key), op.Input, op.Output), nil }
// } return NewDominoOp(string(pop.Key), op.Input, op.Output), nil
}
func (dop DominoOp) ProofOp() ProofOp { func (dop DominoOp) ProofOp() ProofOp {
bz := amino.MustMarshalBinaryLengthPrefixed(dop) bz := amino.MustMarshalBinaryLengthPrefixed(dop)

View File

@ -2,6 +2,8 @@ package clist
import ( import (
"fmt" "fmt"
"runtime"
"sync/atomic"
"testing" "testing"
"time" "time"
@ -65,98 +67,100 @@ func TestSmall(t *testing.T) {
// This test is quite hacky because it relies on SetFinalizer // This test is quite hacky because it relies on SetFinalizer
// which isn't guaranteed to run at all. // which isn't guaranteed to run at all.
//func TestGCFifo(t *testing.T) { //nolint:unused,deadcode
// if runtime.GOARCH != "amd64" { func _TestGCFifo(t *testing.T) {
// t.Skipf("Skipping on non-amd64 machine") if runtime.GOARCH != "amd64" {
// } t.Skipf("Skipping on non-amd64 machine")
}
// const numElements = 1000000 const numElements = 1000000
// l := New() l := New()
// gcCount := new(uint64) gcCount := new(uint64)
// // SetFinalizer doesn't work well with circular structures, // SetFinalizer doesn't work well with circular structures,
// // so we construct a trivial non-circular structure to // so we construct a trivial non-circular structure to
// // track. // track.
// type value struct { type value struct {
// Int int Int int
// } }
// done := make(chan struct{}) done := make(chan struct{})
// for i := 0; i < numElements; i++ { for i := 0; i < numElements; i++ {
// v := new(value) v := new(value)
// v.Int = i v.Int = i
// l.PushBack(v) l.PushBack(v)
// runtime.SetFinalizer(v, func(v *value) { runtime.SetFinalizer(v, func(v *value) {
// atomic.AddUint64(gcCount, 1) atomic.AddUint64(gcCount, 1)
// }) })
// } }
// for el := l.Front(); el != nil; { for el := l.Front(); el != nil; {
// l.Remove(el) l.Remove(el)
// //oldEl := el //oldEl := el
// el = el.Next() el = el.Next()
// //oldEl.DetachPrev() //oldEl.DetachPrev()
// //oldEl.DetachNext() //oldEl.DetachNext()
// } }
// runtime.GC() runtime.GC()
// time.Sleep(time.Second * 3) time.Sleep(time.Second * 3)
// runtime.GC() runtime.GC()
// time.Sleep(time.Second * 3) time.Sleep(time.Second * 3)
// _ = done _ = done
// if *gcCount != numElements { if *gcCount != numElements {
// t.Errorf("Expected gcCount to be %v, got %v", numElements, t.Errorf("Expected gcCount to be %v, got %v", numElements,
// *gcCount) *gcCount)
// } }
//} }
// This test is quite hacky because it relies on SetFinalizer // This test is quite hacky because it relies on SetFinalizer
// which isn't guaranteed to run at all. // which isn't guaranteed to run at all.
// func TestGCRandom(t *testing.T) { //nolint:unused,deadcode
// if runtime.GOARCH != "amd64" { func TestGCRandom(t *testing.T) {
// t.Skipf("Skipping on non-amd64 machine") if runtime.GOARCH != "amd64" {
// } t.Skipf("Skipping on non-amd64 machine")
}
// const numElements = 1000000 const numElements = 1000000
// l := New() l := New()
// gcCount := 0 gcCount := 0
// // SetFinalizer doesn't work well with circular structures, // SetFinalizer doesn't work well with circular structures,
// // so we construct a trivial non-circular structure to // so we construct a trivial non-circular structure to
// // track. // track.
// type value struct { type value struct {
// Int int Int int
// } }
// for i := 0; i < numElements; i++ { for i := 0; i < numElements; i++ {
// v := new(value) v := new(value)
// v.Int = i v.Int = i
// l.PushBack(v) l.PushBack(v)
// runtime.SetFinalizer(v, func(v *value) { runtime.SetFinalizer(v, func(v *value) {
// gcCount++ gcCount++
// }) })
// } }
// els := make([]*CElement, 0, numElements) els := make([]*CElement, 0, numElements)
// for el := l.Front(); el != nil; el = el.Next() { for el := l.Front(); el != nil; el = el.Next() {
// els = append(els, el) els = append(els, el)
// } }
// for _, i := range cmn.RandPerm(numElements) { for _, i := range cmn.RandPerm(numElements) {
// el := els[i] el := els[i]
// l.Remove(el) l.Remove(el)
// _ = el.Next() _ = el.Next()
// } }
// runtime.GC() runtime.GC()
// time.Sleep(time.Second * 3) time.Sleep(time.Second * 3)
// if gcCount != numElements { if gcCount != numElements {
// t.Errorf("Expected gcCount to be %v, got %v", numElements, t.Errorf("Expected gcCount to be %v, got %v", numElements,
// gcCount) gcCount)
// } }
// } }
func TestScanRightDeleteRandom(t *testing.T) { func TestScanRightDeleteRandom(t *testing.T) {

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"testing" "testing"
"time"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -20,7 +21,8 @@ import (
var node *nm.Node var node *nm.Node
var chainID = "tendermint_test" // TODO use from config. var chainID = "tendermint_test" // TODO use from config.
// var waitForEventTimeout = 5 * time.Second //nolint:unused
var waitForEventTimeout = 5 * time.Second
// TODO fix tests!! // TODO fix tests!!
@ -41,83 +43,84 @@ func kvstoreTx(k, v []byte) []byte {
// TODO: enable it after general proof format has been adapted // TODO: enable it after general proof format has been adapted
// in abci/examples/kvstore.go // in abci/examples/kvstore.go
// func TestAppProofs(t *testing.T) { //nolint:unused,deadcode
// assert, require := assert.New(t), require.New(t) func _TestAppProofs(t *testing.T) {
assert, require := assert.New(t), require.New(t)
// prt := defaultProofRuntime() prt := defaultProofRuntime()
// cl := client.NewLocal(node) cl := client.NewLocal(node)
// client.WaitForHeight(cl, 1, nil) client.WaitForHeight(cl, 1, nil)
// // This sets up our trust on the node based on some past point. // This sets up our trust on the node based on some past point.
// source := certclient.NewProvider(chainID, cl) source := certclient.NewProvider(chainID, cl)
// seed, err := source.LatestFullCommit(chainID, 1, 1) seed, err := source.LatestFullCommit(chainID, 1, 1)
// require.NoError(err, "%#v", err) require.NoError(err, "%#v", err)
// cert := lite.NewBaseVerifier(chainID, seed.Height(), seed.Validators) cert := lite.NewBaseVerifier(chainID, seed.Height(), seed.Validators)
// // Wait for tx confirmation. // Wait for tx confirmation.
// done := make(chan int64) done := make(chan int64)
// go func() { go func() {
// evtTyp := types.EventTx evtTyp := types.EventTx
// _, err = client.WaitForOneEvent(cl, evtTyp, waitForEventTimeout) _, err = client.WaitForOneEvent(cl, evtTyp, waitForEventTimeout)
// require.Nil(err, "%#v", err) require.Nil(err, "%#v", err)
// close(done) close(done)
// }() }()
// // Submit a transaction. // Submit a transaction.
// k := []byte("my-key") k := []byte("my-key")
// v := []byte("my-value") v := []byte("my-value")
// tx := kvstoreTx(k, v) tx := kvstoreTx(k, v)
// br, err := cl.BroadcastTxCommit(tx) br, err := cl.BroadcastTxCommit(tx)
// require.NoError(err, "%#v", err) require.NoError(err, "%#v", err)
// require.EqualValues(0, br.CheckTx.Code, "%#v", br.CheckTx) require.EqualValues(0, br.CheckTx.Code, "%#v", br.CheckTx)
// require.EqualValues(0, br.DeliverTx.Code) require.EqualValues(0, br.DeliverTx.Code)
// brh := br.Height brh := br.Height
// // Fetch latest after tx commit. // Fetch latest after tx commit.
// <-done <-done
// latest, err := source.LatestFullCommit(chainID, 1, 1<<63-1) latest, err := source.LatestFullCommit(chainID, 1, 1<<63-1)
// require.NoError(err, "%#v", err) require.NoError(err, "%#v", err)
// rootHash := latest.SignedHeader.AppHash rootHash := latest.SignedHeader.AppHash
// if rootHash == nil { if rootHash == nil {
// // Fetch one block later, AppHash hasn't been committed yet. // Fetch one block later, AppHash hasn't been committed yet.
// // TODO find a way to avoid doing this. // TODO find a way to avoid doing this.
// client.WaitForHeight(cl, latest.SignedHeader.Height+1, nil) client.WaitForHeight(cl, latest.SignedHeader.Height+1, nil)
// latest, err = source.LatestFullCommit(chainID, latest.SignedHeader.Height+1, 1<<63-1) latest, err = source.LatestFullCommit(chainID, latest.SignedHeader.Height+1, 1<<63-1)
// require.NoError(err, "%#v", err) require.NoError(err, "%#v", err)
// rootHash = latest.SignedHeader.AppHash rootHash = latest.SignedHeader.AppHash
// } }
// require.NotNil(rootHash) require.NotNil(rootHash)
// // verify a query before the tx block has no data (and valid non-exist proof) // verify a query before the tx block has no data (and valid non-exist proof)
// bs, height, proof, err := GetWithProof(prt, k, brh-1, cl, cert) bs, height, proof, err := GetWithProof(prt, k, brh-1, cl, cert)
// require.NoError(err, "%#v", err) require.NoError(err, "%#v", err)
// // require.NotNil(proof) // require.NotNil(proof)
// // TODO: Ensure that *some* keys will be there, ensuring that proof is nil, // TODO: Ensure that *some* keys will be there, ensuring that proof is nil,
// // (currently there's a race condition) // (currently there's a race condition)
// // and ensure that proof proves absence of k. // and ensure that proof proves absence of k.
// require.Nil(bs) require.Nil(bs)
// // but given that block it is good // but given that block it is good
// bs, height, proof, err = GetWithProof(prt, k, brh, cl, cert) bs, height, proof, err = GetWithProof(prt, k, brh, cl, cert)
// require.NoError(err, "%#v", err) require.NoError(err, "%#v", err)
// require.NotNil(proof) require.NotNil(proof)
// require.Equal(height, brh) require.Equal(height, brh)
// assert.EqualValues(v, bs) assert.EqualValues(v, bs)
// err = prt.VerifyValue(proof, rootHash, string(k), bs) // XXX key encoding err = prt.VerifyValue(proof, rootHash, string(k), bs) // XXX key encoding
// assert.NoError(err, "%#v", err) assert.NoError(err, "%#v", err)
// // Test non-existing key. // Test non-existing key.
// missing := []byte("my-missing-key") missing := []byte("my-missing-key")
// bs, _, proof, err = GetWithProof(prt, missing, 0, cl, cert) bs, _, proof, err = GetWithProof(prt, missing, 0, cl, cert)
// require.NoError(err) require.NoError(err)
// require.Nil(bs) require.Nil(bs)
// require.NotNil(proof) require.NotNil(proof)
// err = prt.VerifyAbsence(proof, rootHash, string(missing)) // XXX VerifyAbsence(), keyencoding err = prt.VerifyAbsence(proof, rootHash, string(missing)) // XXX VerifyAbsence(), keyencoding
// assert.NoError(err, "%#v", err) assert.NoError(err, "%#v", err)
// err = prt.VerifyAbsence(proof, rootHash, string(k)) // XXX VerifyAbsence(), keyencoding err = prt.VerifyAbsence(proof, rootHash, string(k)) // XXX VerifyAbsence(), keyencoding
// assert.Error(err, "%#v", err) assert.Error(err, "%#v", err)
// } }
func TestTxProofs(t *testing.T) { func TestTxProofs(t *testing.T) {
assert, require := assert.New(t), require.New(t) assert, require := assert.New(t), require.New(t)

View File

@ -65,44 +65,45 @@ func TestTrustMetricCopyNilPointer(t *testing.T) {
} }
// XXX: This test fails non-deterministically // XXX: This test fails non-deterministically
// func _TestTrustMetricStopPause(t *testing.T) { //nolint:unused,deadcode
// // The TestTicker will provide manual control over func _TestTrustMetricStopPause(t *testing.T) {
// // the passing of time within the metric // The TestTicker will provide manual control over
// tt := NewTestTicker() // the passing of time within the metric
// tm := NewMetric() tt := NewTestTicker()
// tm.SetTicker(tt) tm := NewMetric()
// tm.Start() tm.SetTicker(tt)
// // Allow some time intervals to pass and pause tm.Start()
// tt.NextTick() // Allow some time intervals to pass and pause
// tt.NextTick() tt.NextTick()
// tm.Pause() tt.NextTick()
tm.Pause()
// // could be 1 or 2 because Pause and NextTick race // could be 1 or 2 because Pause and NextTick race
// first := tm.Copy().numIntervals first := tm.Copy().numIntervals
// // Allow more time to pass and check the intervals are unchanged // Allow more time to pass and check the intervals are unchanged
// tt.NextTick() tt.NextTick()
// tt.NextTick() tt.NextTick()
// assert.Equal(t, first, tm.Copy().numIntervals) assert.Equal(t, first, tm.Copy().numIntervals)
// // Get the trust metric activated again // Get the trust metric activated again
// tm.GoodEvents(5) tm.GoodEvents(5)
// // Allow some time intervals to pass and stop // Allow some time intervals to pass and stop
// tt.NextTick() tt.NextTick()
// tt.NextTick() tt.NextTick()
// tm.Stop() tm.Stop()
// tm.Wait() tm.Wait()
// second := tm.Copy().numIntervals second := tm.Copy().numIntervals
// // Allow more intervals to pass while the metric is stopped // Allow more intervals to pass while the metric is stopped
// // and check that the number of intervals match // and check that the number of intervals match
// tm.NextTimeInterval() tm.NextTimeInterval()
// tm.NextTimeInterval() tm.NextTimeInterval()
// // XXX: fails non-deterministically: // XXX: fails non-deterministically:
// // expected 5, got 6 // expected 5, got 6
// assert.Equal(t, second+2, tm.Copy().numIntervals) assert.Equal(t, second+2, tm.Copy().numIntervals)
// if first > second { if first > second {
// t.Fatalf("numIntervals should always increase or stay the same over time") t.Fatalf("numIntervals should always increase or stay the same over time")
// } }
// } }