From 5d1459b5847d65069b776be3b4ba5e81bc933dcc Mon Sep 17 00:00:00 2001 From: Marko Date: Sun, 14 Jul 2019 15:50:33 +0200 Subject: [PATCH 1/2] libs/fail: clean up `fail.go` (#3785) * Clean up `fail.go` - Clean up fail.go - Remove unneeded Func `FailRand()` closes #2729 Signed-off-by: Marko Baricevic * add in commented lines --- CHANGELOG_PENDING.md | 1 + libs/fail/fail.go | 47 +++++++------------------------------------- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index d387f9ecb..5131a38ab 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -23,6 +23,7 @@ program](https://hackerone.com/tendermint). - [libs] Remove unused `db/debugDB` and `common/colors.go` & `errors/errors.go` files (@marbar3778) - [libs] \#2432 Remove unused `common/heap.go` file (@marbar3778) - [libs] Remove unused `date.go`, `io.go`. Remove `GoPath()`, `Prompt()` and `IsDirEmpty()` functions from `os.go` (@marbar3778) + - [libs] Remove unused `FailRand()` func and minor clean up to `fail.go`(@marbar3778) - Blockchain Protocol diff --git a/libs/fail/fail.go b/libs/fail/fail.go index d7912af5c..0c9220622 100644 --- a/libs/fail/fail.go +++ b/libs/fail/fail.go @@ -2,36 +2,30 @@ package fail import ( "fmt" - "math/rand" "os" "strconv" ) -var callIndexToFail int - -func init() { +func envSet() int { callIndexToFailS := os.Getenv("FAIL_TEST_INDEX") if callIndexToFailS == "" { - callIndexToFail = -1 + return -1 } else { var err error - callIndexToFail, err = strconv.Atoi(callIndexToFailS) + callIndexToFail, err := strconv.Atoi(callIndexToFailS) if err != nil { - callIndexToFail = -1 + return -1 } + return callIndexToFail } } // Fail when FAIL_TEST_INDEX == callIndex -var ( - callIndex int //indexes Fail calls - - callRandIndex int // indexes a run of FailRand calls - callRandIndexToFail = -1 // the callRandIndex to fail on in FailRand -) +var callIndex int //indexes Fail calls func Fail() { + callIndexToFail := envSet() if callIndexToFail < 0 { return } @@ -43,33 +37,6 @@ func Fail() { callIndex += 1 } -// FailRand should be called n successive times. -// It will fail on a random one of those calls -// n must be greater than 0 -func FailRand(n int) { - if callIndexToFail < 0 { - return - } - - if callRandIndexToFail < 0 { - // first call in the loop, pick a random index to fail at - callRandIndexToFail = rand.Intn(n) - callRandIndex = 0 - } - - if callIndex == callIndexToFail { - if callRandIndex == callRandIndexToFail { - Exit() - } - } - - callRandIndex += 1 - - if callRandIndex == n { - callIndex += 1 - } -} - func Exit() { fmt.Printf("*** fail-test %d ***\n", callIndex) os.Exit(1) From e0b9298134aba2297f9d17367ab9364b28c3fe18 Mon Sep 17 00:00:00 2001 From: Marko Date: Sun, 14 Jul 2019 16:02:48 +0200 Subject: [PATCH 2/2] libs: minor cleanup (#3794) * more minor cleanup of libs Remove unused `version.go`, `assert.go` and `libs/circle.yml` * Update types/vote_set_test.go Co-Authored-By: Anton Kaliaev * spelling change --- CHANGELOG_PENDING.md | 1 + libs/circle.yml | 21 --------------------- libs/test/assert.go | 14 -------------- libs/version/version.go | 3 --- types/vote_set_test.go | 5 +++-- types/vote_test.go | 1 + 6 files changed, 5 insertions(+), 40 deletions(-) delete mode 100644 libs/circle.yml delete mode 100644 libs/test/assert.go delete mode 100644 libs/version/version.go diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 5131a38ab..0120b03ce 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -23,6 +23,7 @@ program](https://hackerone.com/tendermint). - [libs] Remove unused `db/debugDB` and `common/colors.go` & `errors/errors.go` files (@marbar3778) - [libs] \#2432 Remove unused `common/heap.go` file (@marbar3778) - [libs] Remove unused `date.go`, `io.go`. Remove `GoPath()`, `Prompt()` and `IsDirEmpty()` functions from `os.go` (@marbar3778) + - [libs] Remove unused `version.go`, `assert.go` and `libs/circle.yml` - [libs] Remove unused `FailRand()` func and minor clean up to `fail.go`(@marbar3778) - Blockchain Protocol diff --git a/libs/circle.yml b/libs/circle.yml deleted file mode 100644 index 2b7d1266c..000000000 --- a/libs/circle.yml +++ /dev/null @@ -1,21 +0,0 @@ -machine: - environment: - GOPATH: "${HOME}/.go_workspace" - PROJECT_PARENT_PATH: "$GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME" - PROJECT_PATH: $GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME - hosts: - localhost: 127.0.0.1 - -dependencies: - override: - - mkdir -p "$PROJECT_PARENT_PATH" - - ln -sf "$HOME/$CIRCLE_PROJECT_REPONAME/" "$PROJECT_PATH" - post: - - go version - -test: - override: - - cd $PROJECT_PATH && make get_tools && bash ./test.sh - post: - - cd "$PROJECT_PATH" && bash <(curl -s https://codecov.io/bash) -f coverage.txt - - cd "$PROJECT_PATH" && mv coverage.txt "${CIRCLE_ARTIFACTS}" diff --git a/libs/test/assert.go b/libs/test/assert.go deleted file mode 100644 index a6ffed0ce..000000000 --- a/libs/test/assert.go +++ /dev/null @@ -1,14 +0,0 @@ -package test - -import ( - "testing" -) - -func AssertPanics(t *testing.T, msg string, f func()) { - defer func() { - if err := recover(); err == nil { - t.Errorf("Should have panic'd, but didn't: %v", msg) - } - }() - f() -} diff --git a/libs/version/version.go b/libs/version/version.go deleted file mode 100644 index 6e73a937d..000000000 --- a/libs/version/version.go +++ /dev/null @@ -1,3 +0,0 @@ -package version - -const Version = "0.9.0" diff --git a/types/vote_set_test.go b/types/vote_set_test.go index 59205efc6..2e217e940 100644 --- a/types/vote_set_test.go +++ b/types/vote_set_test.go @@ -4,9 +4,10 @@ import ( "bytes" "testing" + "github.com/stretchr/testify/assert" + "github.com/tendermint/tendermint/crypto" cmn "github.com/tendermint/tendermint/libs/common" - tst "github.com/tendermint/tendermint/libs/test" tmtime "github.com/tendermint/tendermint/types/time" ) @@ -490,7 +491,7 @@ func TestMakeCommit(t *testing.T) { } // MakeCommit should fail. - tst.AssertPanics(t, "Doesn't have +2/3 majority", func() { voteSet.MakeCommit() }) + assert.Panics(t, func() { voteSet.MakeCommit() }, "Doesn't have +2/3 majority") // 7th voted for some other block. { diff --git a/types/vote_test.go b/types/vote_test.go index af8a9625b..b6eb1f586 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + amino "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519"