github.com/quic-go/quic-go@v0.44.0/quic_suite_test.go (about)

     1  package quic
     2  
     3  import (
     4  	"bytes"
     5  	"io"
     6  	"log"
     7  	"runtime/pprof"
     8  	"strings"
     9  	"sync"
    10  	"testing"
    11  
    12  	. "github.com/onsi/ginkgo/v2"
    13  	. "github.com/onsi/gomega"
    14  	"go.uber.org/mock/gomock"
    15  )
    16  
    17  func TestQuicGo(t *testing.T) {
    18  	RegisterFailHandler(Fail)
    19  	RunSpecs(t, "QUIC Suite")
    20  }
    21  
    22  var mockCtrl *gomock.Controller
    23  
    24  var _ = BeforeEach(func() {
    25  	mockCtrl = gomock.NewController(GinkgoT())
    26  
    27  	// reset the sync.Once
    28  	connMuxerOnce = *new(sync.Once)
    29  })
    30  
    31  var _ = BeforeSuite(func() {
    32  	log.SetOutput(io.Discard)
    33  })
    34  
    35  func areServersRunning() bool {
    36  	var b bytes.Buffer
    37  	pprof.Lookup("goroutine").WriteTo(&b, 1)
    38  	return strings.Contains(b.String(), "quic-go.(*baseServer).run")
    39  }
    40  
    41  func areTransportsRunning() bool {
    42  	var b bytes.Buffer
    43  	pprof.Lookup("goroutine").WriteTo(&b, 1)
    44  	return strings.Contains(b.String(), "quic-go.(*Transport).listen")
    45  }
    46  
    47  var _ = AfterEach(func() {
    48  	mockCtrl.Finish()
    49  	Eventually(areServersRunning).Should(BeFalse())
    50  	Eventually(areTransportsRunning()).Should(BeFalse())
    51  })