k8s, tests/load: use all accounts to run load testing

This commit is contained in:
Alan Chen 2017-09-28 16:35:12 +08:00
parent ba30840a71
commit 703a7c0312
2 changed files with 43 additions and 32 deletions

View File

@ -18,39 +18,51 @@ package k8s
import (
"context"
"errors"
"math/big"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/getamis/istanbul-tools/client"
istcommon "github.com/getamis/istanbul-tools/common"
)
type Transactor interface {
SendTransactions(context.Context, common.Address, *big.Int, time.Duration) error
SendTransactions(*client.Client, *big.Int, time.Duration) error
}
func (eth *ethereum) SendTransactions(ctx context.Context, to common.Address, amount *big.Int, duration time.Duration) error {
client := eth.NewClient()
if client == nil {
return errors.New("failed to retrieve client")
}
func (eth *ethereum) SendTransactions(client *client.Client, amount *big.Int, duration time.Duration) error {
var fns []func() error
for i, key := range eth.accounts {
i := i
key := key
nonce, err := client.NonceAt(context.Background(), eth.Address(), nil)
if err != nil {
log.Error("Failed to get nonce", "addr", eth.Address(), "err", err)
return err
}
fn := func() error {
fromAddr := crypto.PubkeyToAddress(key.PublicKey)
toAddr := crypto.PubkeyToAddress(eth.accounts[(i+1)%len(eth.accounts)].PublicKey)
timeout := time.After(duration)
timeout := time.After(duration)
for {
select {
case <-timeout:
return nil
default:
_ = istcommon.SendEther(client, eth.key, to, amount, nonce)
nonce++
nonce, err := client.NonceAt(context.Background(), fromAddr, nil)
if err != nil {
log.Error("Failed to get nonce", "addr", fromAddr, "err", err)
return err
}
for {
select {
case <-timeout:
return nil
default:
if err := istcommon.SendEther(client, key, toAddr, amount, nonce); err != nil {
return err
}
nonce++
}
}
}
fns = append(fns, fn)
}
return executeInParallel(fns...)
}

View File

@ -17,7 +17,6 @@
package load
import (
"context"
"math/big"
"sync"
"testing"
@ -42,12 +41,10 @@ var _ = Describe("TPS-01: Large amount of transactions", func() {
runTests(numberOfValidators, gaslimit, txpoolSize)
},
tests.Case("2048", 2048),
tests.Case("10240", 10240),
)
},
tests.Case("21000*1000", 21000*1000),
tests.Case("21000*3000", 21000*3000),
)
@ -63,12 +60,14 @@ func runTests(numberOfValidators int, gaslimit int, txpoolSize int) {
blockchain container.Blockchain
sendEtherAddrs map[common.Address]common.Address
duration = 10 * time.Minute
duration = 10 * time.Minute
accountsPerGeth = 30
)
BeforeEach(func() {
blockchain = k8s.NewBlockchain(
numberOfValidators,
accountsPerGeth,
uint64(gaslimit),
k8s.ImageRepository("quay.io/amis/geth"),
k8s.ImageTag("istanbul_develop"),
@ -104,13 +103,13 @@ func runTests(numberOfValidators int, gaslimit int, txpoolSize int) {
transactor, ok := geth.(k8s.Transactor)
Expect(ok).To(BeTrue())
Expect(
transactor.SendTransactions(
context.Background(),
sendEtherAddrs[geth.Address()],
new(big.Int).Exp(big.NewInt(10), big.NewInt(3), nil),
duration),
).To(BeNil())
client := geth.NewClient()
Expect(client).NotTo(BeNil())
Expect(transactor.SendTransactions(
client,
new(big.Int).Exp(big.NewInt(10), big.NewInt(3), nil),
duration)).To(BeNil())
wg.Done()
})