github.com/defanghe/fabric@v2.1.1+incompatible/orderer/consensus/kafka/retry_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package kafka 8 9 import ( 10 "fmt" 11 "testing" 12 13 "github.com/stretchr/testify/assert" 14 ) 15 16 func TestRetry(t *testing.T) { 17 var rp *retryProcess 18 19 mockChannel := newChannel(channelNameForTest(t), defaultPartition) 20 flag := false 21 22 noErrorFn := func() error { 23 flag = true 24 return nil 25 } 26 27 errorFn := func() error { return fmt.Errorf("foo") } 28 29 t.Run("Proper", func(t *testing.T) { 30 exitChan := make(chan struct{}) 31 rp = newRetryProcess(mockRetryOptions, exitChan, mockChannel, "foo", noErrorFn) 32 assert.NoError(t, rp.retry(), "Expected retry to return no errors") 33 assert.Equal(t, true, flag, "Expected flag to be set to true") 34 }) 35 36 t.Run("WithError", func(t *testing.T) { 37 exitChan := make(chan struct{}) 38 rp = newRetryProcess(mockRetryOptions, exitChan, mockChannel, "foo", errorFn) 39 assert.Error(t, rp.retry(), "Expected retry to return an error") 40 }) 41 }