container, tests: functional test refactoring

This commit is contained in:
Alan Chen 2017-09-01 11:26:54 +08:00
parent a0afc777ba
commit b6925cdc08
10 changed files with 52 additions and 43 deletions

View File

@ -251,7 +251,7 @@ func (eth *ethereum) Start() error {
for i := 0; i < healthCheckRetryCount; i++ {
cli := eth.NewClient()
if cli == nil {
time.Sleep(healthCheckRetryDelay)
<-time.After(healthCheckRetryDelay)
continue
}
_, err = cli.BlockByNumber(context.Background(), big.NewInt(0))

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package tests
package functional
import (
"context"
@ -25,6 +25,7 @@ import (
. "github.com/onsi/gomega"
"github.com/getamis/istanbul-tools/container"
"github.com/getamis/istanbul-tools/tests"
)
var _ = Describe("Block synchronization testing", func() {
@ -45,7 +46,7 @@ var _ = Describe("Block synchronization testing", func() {
blockchain.Finalize()
})
Describe("TFS-06: block synchronization testing", func() {
Describe("TFS-06: Block synchronization testing", func() {
const numberOfNodes = 2
var nodes []container.Ethereum
@ -77,17 +78,19 @@ var _ = Describe("Block synchronization testing", func() {
})
It("TFS-06-01: Node connection", func(done Done) {
By("Connect all nodes to the validators")
for _, n := range nodes {
for _, v := range blockchain.Validators() {
Expect(n.AddPeer(v.NodeAddress())).To(BeNil())
By("Connect all nodes to the validators", func() {
for _, n := range nodes {
for _, v := range blockchain.Validators() {
Expect(n.AddPeer(v.NodeAddress())).To(BeNil())
}
}
}
})
By("Wait for p2p connection")
waitFor(nodes, func(node container.Ethereum, wg *sync.WaitGroup) {
Expect(node.WaitForPeersConnected(numberOfValidators)).To(BeNil())
wg.Done()
By("Wait for p2p connection", func() {
tests.WaitFor(nodes, func(node container.Ethereum, wg *sync.WaitGroup) {
Expect(node.WaitForPeersConnected(numberOfValidators)).To(BeNil())
wg.Done()
})
})
close(done)
@ -97,7 +100,7 @@ var _ = Describe("Block synchronization testing", func() {
const targetBlockHeight = 10
By("Wait for blocks", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlocks(targetBlockHeight)).To(BeNil())
wg.Done()
})
@ -122,14 +125,14 @@ var _ = Describe("Block synchronization testing", func() {
})
By("Wait for p2p connection", func() {
waitFor(nodes, func(node container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(nodes, func(node container.Ethereum, wg *sync.WaitGroup) {
Expect(node.WaitForPeersConnected(numberOfValidators)).To(BeNil())
wg.Done()
})
})
By("Wait for block synchronization between nodes and validators", func() {
waitFor(nodes, func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(nodes, func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlockHeight(targetBlockHeight)).To(BeNil())
wg.Done()
})

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package tests
package functional
import (
"sync"
@ -24,6 +24,7 @@ import (
. "github.com/onsi/gomega"
"github.com/getamis/istanbul-tools/container"
"github.com/getamis/istanbul-tools/tests"
)
var _ = Describe("TFS-05: Byzantine Faulty", func() {
@ -49,7 +50,7 @@ var _ = Describe("TFS-05: Byzantine Faulty", func() {
It("Should generate blocks", func(done Done) {
By("Wait for p2p connection", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForPeersConnected(numberOfNormal + numberOfFaulty - 1)).To(BeNil())
wg.Done()
})
@ -57,7 +58,7 @@ var _ = Describe("TFS-05: Byzantine Faulty", func() {
By("Wait for blocks", func() {
const targetBlockHeight = 3
waitFor(blockchain.Validators()[:1], func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators()[:1], func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlocks(targetBlockHeight)).To(BeNil())
wg.Done()
})
@ -87,7 +88,7 @@ var _ = Describe("TFS-05: Byzantine Faulty", func() {
It("Should not generate blocks", func(done Done) {
By("Wait for p2p connection", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForPeersConnected(numberOfNormal + numberOfFaulty - 1)).To(BeNil())
wg.Done()
})
@ -95,7 +96,7 @@ var _ = Describe("TFS-05: Byzantine Faulty", func() {
By("Wait for blocks", func() {
// Only check normal validators
waitFor(blockchain.Validators()[:2], func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators()[:2], func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForNoBlocks(0, time.Second*30)).To(BeNil())
wg.Done()
})

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package tests
package functional
import (
"context"
@ -26,6 +26,7 @@ import (
. "github.com/onsi/gomega"
"github.com/getamis/istanbul-tools/container"
"github.com/getamis/istanbul-tools/tests"
)
var _ = Describe("Dynamic validators addition/removal testing", func() {
@ -64,7 +65,7 @@ var _ = Describe("Dynamic validators addition/removal testing", func() {
})
By("Wait for several blocks", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlocks(5)).To(BeNil())
wg.Done()
})
@ -86,7 +87,7 @@ var _ = Describe("Dynamic validators addition/removal testing", func() {
newValidators, err := blockchain.AddValidators(testValidator)
Expect(err).Should(BeNil())
waitFor(blockchain.Validators()[numberOfValidators:], func(eth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators()[numberOfValidators:], func(eth container.Ethereum, wg *sync.WaitGroup) {
Expect(eth.WaitForProposed(newValidators[0].Address(), 100*time.Second)).Should(BeNil())
wg.Done()
})
@ -149,7 +150,7 @@ var _ = Describe("Dynamic validators addition/removal testing", func() {
It("TFS-02-04 Reduce validator network size below 2F+1", func() {
By("Ensure that blocks are generated by validators", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlocks(5)).To(BeNil())
wg.Done()
})
@ -174,7 +175,7 @@ var _ = Describe("Dynamic validators addition/removal testing", func() {
})
By("Ensure that blocks are generated by validators", func() {
waitFor(blockchain.Validators()[:numberOfValidators-1], func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators()[:numberOfValidators-1], func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlocks(5)).To(BeNil())
wg.Done()
})
@ -183,7 +184,7 @@ var _ = Describe("Dynamic validators addition/removal testing", func() {
It("TFS-02-05 Reduce validator network size below 2F+1", func() {
By("Ensure that blocks are generated by validators", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlocks(5)).To(BeNil())
wg.Done()
})

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package tests
package functional
import (
"context"
@ -30,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/getamis/istanbul-tools/container"
"github.com/getamis/istanbul-tools/genesis"
"github.com/getamis/istanbul-tools/tests"
)
var _ = Describe("TFS-01: General consensus", func() {
@ -113,7 +114,7 @@ var _ = Describe("TFS-01: General consensus", func() {
It("TFS-01-03: Peer connection", func(done Done) {
expectedPeerCount := len(blockchain.Validators()) - 1
waitFor(blockchain.Validators(), func(v container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(v container.Ethereum, wg *sync.WaitGroup) {
Expect(v.WaitForPeersConnected(expectedPeerCount)).To(BeNil())
wg.Done()
})
@ -128,7 +129,7 @@ var _ = Describe("TFS-01: General consensus", func() {
)
By("Wait for consensus progress", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlockHeight(targetBlockHeight)).To(BeNil())
wg.Done()
})
@ -179,7 +180,7 @@ var _ = Describe("TFS-01: General consensus", func() {
)
By("Wait for consensus progress", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlockHeight(targetBlockHeight)).To(BeNil())
wg.Done()
})

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package tests
package functional
import (
"context"
@ -24,6 +24,7 @@ import (
. "github.com/onsi/gomega"
"github.com/getamis/istanbul-tools/container"
"github.com/getamis/istanbul-tools/tests"
)
var _ = Describe("TFS-07: Gossip Network", func() {
@ -55,7 +56,7 @@ var _ = Describe("TFS-07: Gossip Network", func() {
})
By("Checking blockchain progress", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlocks(3)).To(BeNil())
wg.Done()
})

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package tests
package functional
import (
"testing"

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package tests
package functional
import (
"sync"
@ -24,6 +24,7 @@ import (
. "github.com/onsi/gomega"
"github.com/getamis/istanbul-tools/container"
"github.com/getamis/istanbul-tools/tests"
)
var _ = Describe("TFS-04: Non-Byzantine Faulty", func() {
@ -46,7 +47,7 @@ var _ = Describe("TFS-04: Non-Byzantine Faulty", func() {
It("TFS-04-01: Stop F validators", func(done Done) {
By("Generating blockchain progress before stopping validator", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlocks(3)).To(BeNil())
wg.Done()
})
@ -68,7 +69,7 @@ var _ = Describe("TFS-04: Non-Byzantine Faulty", func() {
})
By("Checking blockchain progress after stopping validator", func() {
waitFor(blockchain.Validators()[1:], func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators()[1:], func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlocks(3)).To(BeNil())
wg.Done()
})

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package tests
package functional
import (
"sync"
@ -24,6 +24,7 @@ import (
. "github.com/onsi/gomega"
"github.com/getamis/istanbul-tools/container"
"github.com/getamis/istanbul-tools/tests"
)
var _ = Describe("TFS-03: Recoverability testing", func() {
@ -46,7 +47,7 @@ var _ = Describe("TFS-03: Recoverability testing", func() {
It("TFS-04-01: Add validators in a network with < 2F+1 validators to > 2F+1", func(done Done) {
By("The consensus should work at the beginning", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlocks(5)).To(BeNil())
wg.Done()
})
@ -55,14 +56,14 @@ var _ = Describe("TFS-03: Recoverability testing", func() {
numOfValidatorsToBeStopped := 2
By("Stop several validators until there are less than 2F+1 validators", func() {
waitFor(blockchain.Validators()[:numOfValidatorsToBeStopped], func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators()[:numOfValidatorsToBeStopped], func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.StopMining()).To(BeNil())
wg.Done()
})
})
By("The consensus should not work after resuming", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
// container.ErrNoBlock should be returned if we didn't see any block in 10 seconds
Expect(geth.WaitForBlocks(1, 10*time.Second)).To(BeEquivalentTo(container.ErrNoBlock))
wg.Done()
@ -70,14 +71,14 @@ var _ = Describe("TFS-03: Recoverability testing", func() {
})
By("Resume the stopped validators", func() {
waitFor(blockchain.Validators()[:numOfValidatorsToBeStopped], func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators()[:numOfValidatorsToBeStopped], func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.StartMining()).To(BeNil())
wg.Done()
})
})
By("The consensus should work after resuming", func() {
waitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) {
Expect(geth.WaitForBlocks(5)).To(BeNil())
wg.Done()
})

View File

@ -22,7 +22,7 @@ import (
"github.com/getamis/istanbul-tools/container"
)
func waitFor(geths []container.Ethereum, waitFn func(eth container.Ethereum, wg *sync.WaitGroup)) {
func WaitFor(geths []container.Ethereum, waitFn func(eth container.Ethereum, wg *sync.WaitGroup)) {
wg := new(sync.WaitGroup)
for _, g := range geths {
wg.Add(1)