github.com/myafeier/fabric@v1.0.1-0.20170722181825-3a4b1f2bce86/core/comm/config_test.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package comm
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/spf13/viper"
    13  	"github.com/stretchr/testify/assert"
    14  )
    15  
    16  func TestConfig(t *testing.T) {
    17  	// check the defaults
    18  	assert.EqualValues(t, maxRecvMsgSize, MaxRecvMsgSize())
    19  	assert.EqualValues(t, maxSendMsgSize, MaxSendMsgSize())
    20  	assert.EqualValues(t, false, TLSEnabled())
    21  	assert.EqualValues(t, true, configurationCached)
    22  
    23  	// set send/recv msg sizes
    24  	size := 10 * 1024 * 1024
    25  	SetMaxRecvMsgSize(size)
    26  	SetMaxSendMsgSize(size)
    27  	assert.EqualValues(t, size, MaxRecvMsgSize())
    28  	assert.EqualValues(t, size, MaxSendMsgSize())
    29  
    30  	// set keepalive options
    31  	timeout := 1000
    32  	ka := KeepaliveOptions{
    33  		ClientKeepaliveTime:    timeout,
    34  		ClientKeepaliveTimeout: timeout + 1,
    35  		ServerKeepaliveTime:    timeout + 2,
    36  		ServerKeepaliveTimeout: timeout + 3,
    37  	}
    38  	SetKeepaliveOptions(ka)
    39  	assert.EqualValues(t, timeout, keepaliveOptions.ClientKeepaliveTime)
    40  	assert.EqualValues(t, timeout+1, keepaliveOptions.ClientKeepaliveTimeout)
    41  	assert.EqualValues(t, timeout+2, keepaliveOptions.ServerKeepaliveTime)
    42  	assert.EqualValues(t, timeout+3, keepaliveOptions.ServerKeepaliveTimeout)
    43  	assert.EqualValues(t, 2, len(ServerKeepaliveOptions()))
    44  	assert.Equal(t, 1, len(ClientKeepaliveOptions()))
    45  
    46  	// reset cache
    47  	configurationCached = false
    48  	viper.Set("peer.tls.enabled", true)
    49  	assert.EqualValues(t, true, TLSEnabled())
    50  	// check that value is cached
    51  	viper.Set("peer.tls.enabled", false)
    52  	assert.NotEqual(t, false, TLSEnabled())
    53  	// reset tls
    54  	configurationCached = false
    55  	viper.Set("peer.tls.enabled", false)
    56  }