k8s, tests/load: use all accounts to run load testing
This commit is contained in:
parent
ba30840a71
commit
703a7c0312
|
@ -18,39 +18,51 @@ package k8s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"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"
|
istcommon "github.com/getamis/istanbul-tools/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Transactor interface {
|
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 {
|
func (eth *ethereum) SendTransactions(client *client.Client, amount *big.Int, duration time.Duration) error {
|
||||||
client := eth.NewClient()
|
var fns []func() error
|
||||||
if client == nil {
|
for i, key := range eth.accounts {
|
||||||
return errors.New("failed to retrieve client")
|
i := i
|
||||||
}
|
key := key
|
||||||
|
|
||||||
nonce, err := client.NonceAt(context.Background(), eth.Address(), nil)
|
fn := func() error {
|
||||||
if err != nil {
|
fromAddr := crypto.PubkeyToAddress(key.PublicKey)
|
||||||
log.Error("Failed to get nonce", "addr", eth.Address(), "err", err)
|
toAddr := crypto.PubkeyToAddress(eth.accounts[(i+1)%len(eth.accounts)].PublicKey)
|
||||||
return err
|
timeout := time.After(duration)
|
||||||
}
|
|
||||||
|
|
||||||
timeout := time.After(duration)
|
nonce, err := client.NonceAt(context.Background(), fromAddr, nil)
|
||||||
for {
|
if err != nil {
|
||||||
select {
|
log.Error("Failed to get nonce", "addr", fromAddr, "err", err)
|
||||||
case <-timeout:
|
return err
|
||||||
return nil
|
}
|
||||||
default:
|
|
||||||
_ = istcommon.SendEther(client, eth.key, to, amount, nonce)
|
for {
|
||||||
nonce++
|
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...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package load
|
package load
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -42,12 +41,10 @@ var _ = Describe("TPS-01: Large amount of transactions", func() {
|
||||||
runTests(numberOfValidators, gaslimit, txpoolSize)
|
runTests(numberOfValidators, gaslimit, txpoolSize)
|
||||||
},
|
},
|
||||||
|
|
||||||
tests.Case("2048", 2048),
|
|
||||||
tests.Case("10240", 10240),
|
tests.Case("10240", 10240),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
tests.Case("21000*1000", 21000*1000),
|
|
||||||
tests.Case("21000*3000", 21000*3000),
|
tests.Case("21000*3000", 21000*3000),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -63,12 +60,14 @@ func runTests(numberOfValidators int, gaslimit int, txpoolSize int) {
|
||||||
blockchain container.Blockchain
|
blockchain container.Blockchain
|
||||||
sendEtherAddrs map[common.Address]common.Address
|
sendEtherAddrs map[common.Address]common.Address
|
||||||
|
|
||||||
duration = 10 * time.Minute
|
duration = 10 * time.Minute
|
||||||
|
accountsPerGeth = 30
|
||||||
)
|
)
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
blockchain = k8s.NewBlockchain(
|
blockchain = k8s.NewBlockchain(
|
||||||
numberOfValidators,
|
numberOfValidators,
|
||||||
|
accountsPerGeth,
|
||||||
uint64(gaslimit),
|
uint64(gaslimit),
|
||||||
k8s.ImageRepository("quay.io/amis/geth"),
|
k8s.ImageRepository("quay.io/amis/geth"),
|
||||||
k8s.ImageTag("istanbul_develop"),
|
k8s.ImageTag("istanbul_develop"),
|
||||||
|
@ -104,13 +103,13 @@ func runTests(numberOfValidators int, gaslimit int, txpoolSize int) {
|
||||||
transactor, ok := geth.(k8s.Transactor)
|
transactor, ok := geth.(k8s.Transactor)
|
||||||
Expect(ok).To(BeTrue())
|
Expect(ok).To(BeTrue())
|
||||||
|
|
||||||
Expect(
|
client := geth.NewClient()
|
||||||
transactor.SendTransactions(
|
Expect(client).NotTo(BeNil())
|
||||||
context.Background(),
|
|
||||||
sendEtherAddrs[geth.Address()],
|
Expect(transactor.SendTransactions(
|
||||||
new(big.Int).Exp(big.NewInt(10), big.NewInt(3), nil),
|
client,
|
||||||
duration),
|
new(big.Int).Exp(big.NewInt(10), big.NewInt(3), nil),
|
||||||
).To(BeNil())
|
duration)).To(BeNil())
|
||||||
|
|
||||||
wg.Done()
|
wg.Done()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue