From 30502d963d3ecb61f05cc033f457b6b4af0b0a84 Mon Sep 17 00:00:00 2001 From: Miya Chen Date: Tue, 3 Oct 2017 16:53:18 +0800 Subject: [PATCH] metrics, tests/load: estimating the remaining number of blocks --- metrics/blockchain.go | 2 +- metrics/exporter.go | 35 +++++++++++++++++++++++++++++++++++ tests/load/load_test.go | 9 ++++++++- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 metrics/exporter.go diff --git a/metrics/blockchain.go b/metrics/blockchain.go index ad464d9b..e1d574a7 100644 --- a/metrics/blockchain.go +++ b/metrics/blockchain.go @@ -142,7 +142,7 @@ func (mc *metricChain) Stop(strong bool) error { sub.Unsubscribe() } mc.wg.Wait() - mc.metricsMgr.Export() + mc.Export() return mc.Blockchain.Stop(strong) } diff --git a/metrics/exporter.go b/metrics/exporter.go new file mode 100644 index 00000000..fb08a363 --- /dev/null +++ b/metrics/exporter.go @@ -0,0 +1,35 @@ +// 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 metrics + +type Exporter interface { + Export() + SentTxCount() int64 + ExcutedTxCount() int64 +} + +func (mc *metricChain) Export() { + mc.metricsMgr.Export() +} + +func (mc *metricChain) SentTxCount() int64 { + return mc.metricsMgr.SentTxCounter.Snapshot().Count() +} + +func (mc *metricChain) ExcutedTxCount() int64 { + return mc.metricsMgr.ExcutedTxCounter.Snapshot().Count() +} diff --git a/tests/load/load_test.go b/tests/load/load_test.go index c039dc5e..f91f64e1 100644 --- a/tests/load/load_test.go +++ b/tests/load/load_test.go @@ -26,6 +26,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + istcommon "github.com/getamis/istanbul-tools/common" "github.com/getamis/istanbul-tools/container" "github.com/getamis/istanbul-tools/k8s" "github.com/getamis/istanbul-tools/metrics" @@ -88,8 +89,14 @@ func runTests(numberOfValidators int, gaslimit int, txpoolSize int) { AfterEach(func() { Expect(blockchain).NotTo(BeNil()) + var blocksCnt int = 5 + metricsExport, ok := blockchain.(metrics.Exporter) + if ok { + blockSize := gaslimit / int(istcommon.DefaultGasLimit) + blocksCnt = int(metricsExport.SentTxCount()-metricsExport.ExcutedTxCount())/blockSize + 1 + } tests.WaitFor(blockchain.Validators(), func(geth container.Ethereum, wg *sync.WaitGroup) { - Expect(geth.WaitForBlocks(10)).To(BeNil()) + Expect(geth.WaitForBlocks(blocksCnt)).To(BeNil()) wg.Done() }) Expect(blockchain.Stop(true)).To(BeNil())