From 1159e96b1f6cbb1970a9d86005ee74b6809ad707 Mon Sep 17 00:00:00 2001 From: Edwin Date: Wed, 6 Sep 2017 10:47:53 +0800 Subject: [PATCH] tests/quorum: add recoverability testing --- .../quorum/functional/recoverability_test.go | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 tests/quorum/functional/recoverability_test.go diff --git a/tests/quorum/functional/recoverability_test.go b/tests/quorum/functional/recoverability_test.go new file mode 100644 index 00000000..0658bc65 --- /dev/null +++ b/tests/quorum/functional/recoverability_test.go @@ -0,0 +1,94 @@ +// Copyright 2017 AMIS Technologies +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +package functional + +import ( + "sync" + "time" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "github.com/getamis/istanbul-tools/container" + "github.com/getamis/istanbul-tools/tests" +) + +var _ = Describe("QFS-03: Recoverability testing", func() { + const ( + numberOfValidators = 4 + ) + var ( + constellationNetwork container.ConstellationNetwork + blockchain container.Blockchain + ) + + BeforeEach(func() { + constellationNetwork = container.NewDefaultConstellationNetwork(dockerNetwork, numberOfValidators) + Expect(constellationNetwork.Start()).To(BeNil()) + blockchain = container.NewDefaultQuorumBlockchain(dockerNetwork, constellationNetwork) + Expect(blockchain.Start(true)).To(BeNil()) + }) + + AfterEach(func() { + blockchain.Stop(true) + blockchain.Finalize() + constellationNetwork.Stop() + constellationNetwork.Finalize() + }) + + It("QFS-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() { + tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) { + Expect(geth.WaitForBlocks(5)).To(BeNil()) + wg.Done() + }) + }) + + numOfValidatorsToBeStopped := 2 + + By("Stop several validators until there are less than 2F+1 validators", func() { + 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() { + 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() + }) + }) + + By("Resume the stopped validators", func() { + 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() { + tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) { + Expect(geth.WaitForBlocks(5)).To(BeNil()) + wg.Done() + }) + }) + + close(done) + }, 120) +})