Skip to content

Commit

Permalink
[FAB-2207] Add test case for the wait time config
Browse files Browse the repository at this point in the history
Change-Id: If3b19a173a7423c76f51d2814ee8c14723c505cf
Signed-off-by: Ray Chen <ray@hyperchain.cn>
  • Loading branch information
oldsharp committed Mar 6, 2017
1 parent ed7ed80 commit 59eb56d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions gossip/gossip/algo/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package algo

import (
"strings"
"sync"
"testing"
"time"
Expand All @@ -25,6 +26,7 @@ import (
"sync/atomic"

"github.com/hyperledger/fabric/gossip/util"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -502,6 +504,38 @@ func TestSpread(t *testing.T) {

}

func TestDefaultConfig(t *testing.T) {
preDigestWaitTime := util.GetDurationOrDefault("peer.gossip.digestWaitTime", defDigestWaitTime)
preRequestWaitTime := util.GetDurationOrDefault("peer.gossip.requestWaitTime", defRequestWaitTime)
preResponseWaitTime := util.GetDurationOrDefault("peer.gossip.responseWaitTime", defResponseWaitTime)
defer func() {
SetDigestWaitTime(preDigestWaitTime)
SetRequestWaitTime(preRequestWaitTime)
SetResponseWaitTime(preResponseWaitTime)
}()

// Check if we can read default duration when no properties are
// defined in config file.
viper.Reset()
assert.Equal(t, time.Duration(1)*time.Second, util.GetDurationOrDefault("peer.gossip.digestWaitTime", defDigestWaitTime))
assert.Equal(t, time.Duration(1)*time.Second, util.GetDurationOrDefault("peer.gossip.requestWaitTime", defRequestWaitTime))
assert.Equal(t, time.Duration(2)*time.Second, util.GetDurationOrDefault("peer.gossip.responseWaitTime", defResponseWaitTime))

// Check if the properties in the config file (peer/core.yaml)
// are set to the desired duration.
viper.Reset()
viper.SetConfigName("core")
viper.SetEnvPrefix("CORE")
viper.AddConfigPath("./../../../peer")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
err := viper.ReadInConfig()
assert.NoError(t, err)
assert.Equal(t, time.Duration(1)*time.Second, util.GetDurationOrDefault("peer.gossip.digestWaitTime", defDigestWaitTime))
assert.Equal(t, time.Duration(1)*time.Second, util.GetDurationOrDefault("peer.gossip.requestWaitTime", defRequestWaitTime))
assert.Equal(t, time.Duration(2)*time.Second, util.GetDurationOrDefault("peer.gossip.responseWaitTime", defResponseWaitTime))
}

func Strcmp(a interface{}, b interface{}) bool {
return a.(string) == b.(string)
}
Expand Down

0 comments on commit 59eb56d

Please sign in to comment.