github.com/wangyougui/gf/v2@v2.6.5/net/ghttp/ghttp_z_unit_feature_pprof_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  // static service testing.
     8  
     9  package ghttp_test
    10  
    11  import (
    12  	"fmt"
    13  	"testing"
    14  	"time"
    15  
    16  	"github.com/wangyougui/gf/v2/frame/g"
    17  	. "github.com/wangyougui/gf/v2/test/gtest"
    18  	"github.com/wangyougui/gf/v2/util/guid"
    19  )
    20  
    21  func TestServer_EnablePProf(t *testing.T) {
    22  	C(t, func(t *T) {
    23  		s := g.Server(guid.S())
    24  		s.EnablePProf("/pprof")
    25  		s.SetDumpRouterMap(false)
    26  		s.Start()
    27  		defer s.Shutdown()
    28  		time.Sleep(100 * time.Millisecond)
    29  		client := g.Client()
    30  		client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
    31  
    32  		r, err := client.Get(ctx, "/pprof/index")
    33  		Assert(err, nil)
    34  		Assert(r.StatusCode, 200)
    35  		r.Close()
    36  
    37  		r, err = client.Get(ctx, "/pprof/cmdline")
    38  		Assert(err, nil)
    39  		Assert(r.StatusCode, 200)
    40  		r.Close()
    41  
    42  		//r, err = client.Get(ctx, "/pprof/profile")
    43  		//Assert(err, nil)
    44  		//Assert(r.StatusCode, 200)
    45  		//r.Close()
    46  
    47  		r, err = client.Get(ctx, "/pprof/symbol")
    48  		Assert(err, nil)
    49  		Assert(r.StatusCode, 200)
    50  		r.Close()
    51  
    52  		r, err = client.Get(ctx, "/pprof/trace")
    53  		Assert(err, nil)
    54  		Assert(r.StatusCode, 200)
    55  		r.Close()
    56  	})
    57  
    58  }