container: caller must pass processing time into RemoveValidators function

This commit is contained in:
Edwin 2017-08-23 11:08:42 +08:00
parent b6ee88035a
commit 62232d30c4
2 changed files with 7 additions and 5 deletions

View File

@ -20,7 +20,6 @@ import (
"context"
"crypto/ecdsa"
"log"
"math"
"os"
"path/filepath"
"time"
@ -34,7 +33,7 @@ import (
type Blockchain interface {
AddValidators(numOfValidators int) ([]Ethereum, error)
RemoveValidators(candidates []Ethereum) error
RemoveValidators(candidates []Ethereum, t time.Duration) error
EnsureConsensusWorking(geths []Ethereum, t time.Duration) error
Start(bool) error
Stop(bool) error
@ -111,7 +110,7 @@ func (bc *blockchain) EnsureConsensusWorking(geths []Ethereum, t time.Duration)
return err
}
func (bc *blockchain) RemoveValidators(candidates []Ethereum) error {
func (bc *blockchain) RemoveValidators(candidates []Ethereum, processingTime time.Duration) error {
var newValidators []Ethereum
for _, v := range bc.validators {
@ -131,7 +130,7 @@ func (bc *blockchain) RemoveValidators(candidates []Ethereum) error {
}
// FIXME: It is not good way to wait validator vote out candidates
<-time.After(time.Duration(math.Pow(2, float64(len(candidates)))*7) * time.Second)
<-time.After(processingTime)
bc.validators = newValidators
return bc.stop(candidates, false)

View File

@ -19,6 +19,7 @@ package tests
import (
"context"
"time"
"math"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -111,7 +112,9 @@ var _ = Describe("Dynamic validators addition/removal testing", func() {
}
// remove validators [1,2,3]
Expect(blockchain.RemoveValidators(blockchain.Validators()[:numOfCandidates])).Should(BeNil())
removalCandidates := blockchain.Validators()[:numOfCandidates]
processingTime := time.Duration(math.Pow(2, float64(len(removalCandidates)))*7) * time.Second
Expect(blockchain.RemoveValidators(removalCandidates, processingTime)).Should(BeNil())
By("Ensure that consensus is working in 10 seconds", func() {
Expect(blockchain.EnsureConsensusWorking(blockchain.Validators(), 10*time.Second)).Should(BeNil())
})