github.com/true-sqn/fabric@v2.1.1+incompatible/core/endorser/metrics_test.go (about)

     1  /*
     2  Copyright State Street Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package endorser
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/hyperledger/fabric/common/metrics/metricsfakes"
    13  	. "github.com/onsi/gomega"
    14  )
    15  
    16  func TestNewMetrics(t *testing.T) {
    17  	gt := NewGomegaWithT(t)
    18  
    19  	provider := &metricsfakes.Provider{}
    20  	provider.NewHistogramReturns(&metricsfakes.Histogram{})
    21  	provider.NewCounterReturns(&metricsfakes.Counter{})
    22  
    23  	endorserMetrics := NewMetrics(provider)
    24  	gt.Expect(endorserMetrics).To(Equal(&Metrics{
    25  		ProposalDuration:         &metricsfakes.Histogram{},
    26  		ProposalsReceived:        &metricsfakes.Counter{},
    27  		SuccessfulProposals:      &metricsfakes.Counter{},
    28  		ProposalValidationFailed: &metricsfakes.Counter{},
    29  		ProposalACLCheckFailed:   &metricsfakes.Counter{},
    30  		InitFailed:               &metricsfakes.Counter{},
    31  		EndorsementsFailed:       &metricsfakes.Counter{},
    32  		DuplicateTxsFailure:      &metricsfakes.Counter{},
    33  		SimulationFailure:        &metricsfakes.Counter{},
    34  	}))
    35  
    36  	gt.Expect(provider.NewHistogramCallCount()).To(Equal(1))
    37  	gt.Expect(provider.Invocations()["NewHistogram"]).To(ConsistOf([][]interface{}{
    38  		{proposalDurationHistogramOpts},
    39  	}))
    40  
    41  	gt.Expect(provider.NewCounterCallCount()).To(Equal(8))
    42  	gt.Expect(provider.Invocations()["NewCounter"]).To(ConsistOf([][]interface{}{
    43  		{receivedProposalsCounterOpts},
    44  		{successfulProposalsCounterOpts},
    45  		{proposalValidationFailureCounterOpts},
    46  		{proposalChannelACLFailureOpts},
    47  		{initFailureCounterOpts},
    48  		{endorsementFailureCounterOpts},
    49  		{duplicateTxsFailureCounterOpts},
    50  		{simulationFailureCounterOpts},
    51  	}))
    52  }