github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/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  }