github.com/sykesm/fabric@v1.1.0-preview.0.20200129034918-2aa12b1a0181/common/diag/goroutine_test.go (about)

     1  /*
     2  Copyright IBM Corp All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package diag_test
     8  
     9  import (
    10  	"testing"
    11  
    12  	"github.com/hyperledger/fabric/common/diag"
    13  	"github.com/hyperledger/fabric/common/flogging/floggingtest"
    14  	. "github.com/onsi/gomega"
    15  	"github.com/onsi/gomega/gbytes"
    16  )
    17  
    18  func TestCaptureGoRoutines(t *testing.T) {
    19  	gt := NewGomegaWithT(t)
    20  	output, err := diag.CaptureGoRoutines()
    21  	gt.Expect(err).NotTo(HaveOccurred())
    22  
    23  	gt.Expect(output).To(MatchRegexp(`goroutine \d+ \[running\]:`))
    24  	gt.Expect(output).To(ContainSubstring("github.com/hyperledger/fabric/common/diag.CaptureGoRoutines"))
    25  }
    26  
    27  func TestLogGoRoutines(t *testing.T) {
    28  	gt := NewGomegaWithT(t)
    29  	logger, recorder := floggingtest.NewTestLogger(t, floggingtest.Named("goroutine"))
    30  	diag.LogGoRoutines(logger)
    31  
    32  	gt.Expect(recorder).To(gbytes.Say(`goroutine \d+ \[running\]:`))
    33  }