mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-23 01:57:55 +08:00
removed use of sync.pool from HandleContext and added test coverage
This commit is contained in:
parent
ad53619b15
commit
d8b85d20e9
1
gin.go
1
gin.go
@ -336,7 +336,6 @@ func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
func (engine *Engine) HandleContext(c *Context) {
|
func (engine *Engine) HandleContext(c *Context) {
|
||||||
c.reset()
|
c.reset()
|
||||||
engine.handleHTTPRequest(c)
|
engine.handleHTTPRequest(c)
|
||||||
engine.pool.Put(c)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) handleHTTPRequest(c *Context) {
|
func (engine *Engine) handleHTTPRequest(c *Context) {
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -119,6 +120,29 @@ func TestWithHttptestWithAutoSelectedPort(t *testing.T) {
|
|||||||
testRequest(t, ts.URL+"/example")
|
testRequest(t, ts.URL+"/example")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConcurrentHandleContext(t *testing.T) {
|
||||||
|
router := New()
|
||||||
|
router.GET("/", func(c *Context) {
|
||||||
|
c.Request.URL.Path = "/example"
|
||||||
|
router.HandleContext(c)
|
||||||
|
})
|
||||||
|
router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
|
||||||
|
|
||||||
|
ts := httptest.NewServer(router)
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
iterations := 200
|
||||||
|
wg.Add(iterations)
|
||||||
|
for i := 0; i < iterations; i++ {
|
||||||
|
go func() {
|
||||||
|
testRequest(t, ts.URL+"/")
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
// func TestWithHttptestWithSpecifiedPort(t *testing.T) {
|
// func TestWithHttptestWithSpecifiedPort(t *testing.T) {
|
||||||
// router := New()
|
// router := New()
|
||||||
// router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
|
// router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user