github.com/osdi23p228/fabric@v0.0.0-20221218062954-77808885f5db/gossip/state/config_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package state_test
     8  
     9  import (
    10  	"testing"
    11  	"time"
    12  
    13  	"github.com/osdi23p228/fabric/gossip/state"
    14  	"github.com/stretchr/testify/assert"
    15  
    16  	"github.com/spf13/viper"
    17  )
    18  
    19  func TestGlobalConfig(t *testing.T) {
    20  	viper.Reset()
    21  	viper.Set("peer.gossip.state.checkInterval", "1s")
    22  	viper.Set("peer.gossip.state.responseTimeout", "2s")
    23  	viper.Set("peer.gossip.state.batchSize", 3)
    24  	viper.Set("peer.gossip.state.maxRetries", 4)
    25  	viper.Set("peer.gossip.state.blockBufferSize", 5)
    26  	viper.Set("peer.gossip.state.channelSize", 6)
    27  	viper.Set("peer.gossip.state.enabled", true)
    28  
    29  	coreConfig := state.GlobalConfig()
    30  
    31  	expectedConfig := &state.StateConfig{
    32  		StateCheckInterval:   time.Second,
    33  		StateResponseTimeout: 2 * time.Second,
    34  		StateBatchSize:       uint64(3),
    35  		StateMaxRetries:      4,
    36  		StateBlockBufferSize: 5,
    37  		StateChannelSize:     6,
    38  		StateEnabled:         true,
    39  	}
    40  
    41  	assert.Equal(t, expectedConfig, coreConfig)
    42  }
    43  
    44  func TestGlobalConfigDefaults(t *testing.T) {
    45  	viper.Reset()
    46  
    47  	coreConfig := state.GlobalConfig()
    48  
    49  	expectedConfig := &state.StateConfig{
    50  		StateCheckInterval:   10 * time.Second,
    51  		StateResponseTimeout: 3 * time.Second,
    52  		StateBatchSize:       uint64(10),
    53  		StateMaxRetries:      3,
    54  		StateBlockBufferSize: 20,
    55  		StateChannelSize:     100,
    56  		StateEnabled:         false,
    57  	}
    58  
    59  	assert.Equal(t, expectedConfig, coreConfig)
    60  }