github.com/gogf/gf@v1.16.9/net/ghttp/ghttp_unit_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/gogf/gf.
     6  
     7  // static service testing.
     8  
     9  package ghttp_test
    10  
    11  import (
    12  	"fmt"
    13  	"testing"
    14  	"time"
    15  
    16  	"github.com/gogf/gf/frame/g"
    17  	. "github.com/gogf/gf/test/gtest"
    18  )
    19  
    20  func TestServer_EnablePProf(t *testing.T) {
    21  	C(t, func(t *T) {
    22  		p, _ := ports.PopRand()
    23  		s := g.Server(p)
    24  		s.EnablePProf("/pprof")
    25  		s.SetDumpRouterMap(false)
    26  		s.SetPort(p)
    27  		s.Start()
    28  		defer s.Shutdown()
    29  		time.Sleep(100 * time.Millisecond)
    30  		client := g.Client()
    31  		client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
    32  
    33  		r, err := client.Get("/pprof/index")
    34  		Assert(err, nil)
    35  		Assert(r.StatusCode, 200)
    36  		r.Close()
    37  
    38  		r, err = client.Get("/pprof/cmdline")
    39  		Assert(err, nil)
    40  		Assert(r.StatusCode, 200)
    41  		r.Close()
    42  
    43  		//r, err = client.Get("/pprof/profile")
    44  		//Assert(err, nil)
    45  		//Assert(r.StatusCode, 200)
    46  		//r.Close()
    47  
    48  		r, err = client.Get("/pprof/symbol")
    49  		Assert(err, nil)
    50  		Assert(r.StatusCode, 200)
    51  		r.Close()
    52  
    53  		r, err = client.Get("/pprof/trace")
    54  		Assert(err, nil)
    55  		Assert(r.StatusCode, 200)
    56  		r.Close()
    57  	})
    58  
    59  }