MCPcopy
hub / github.com/gin-gonic/gin / TestEngineHandleContextManyReEntries

Function TestEngineHandleContextManyReEntries

gin_test.go:671–706  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

669}
670
671func TestEngineHandleContextManyReEntries(t *testing.T) {
672 expectValue := 10000
673
674 var handlerCounter, middlewareCounter int64
675
676 r := New()
677 r.Use(func(c *Context) {
678 atomic.AddInt64(&middlewareCounter, 1)
679 })
680 r.GET("/:count", func(c *Context) {
681 countStr := c.Param("count")
682 count, err := strconv.Atoi(countStr)
683 require.NoError(t, err)
684
685 n, err := c.Writer.Write([]byte("."))
686 require.NoError(t, err)
687 assert.Equal(t, 1, n)
688
689 switch {
690 case count > 0:
691 c.Request.URL.Path = "/" + strconv.Itoa(count-1)
692 r.HandleContext(c)
693 }
694 }, func(c *Context) {
695 atomic.AddInt64(&handlerCounter, 1)
696 })
697
698 assert.NotPanics(t, func() {
699 w := PerformRequest(r, http.MethodGet, "/"+strconv.Itoa(expectValue-1)) // include 0 value
700 assert.Equal(t, 200, w.Code)
701 assert.Equal(t, expectValue, w.Body.Len())
702 })
703
704 assert.Equal(t, int64(expectValue), handlerCounter)
705 assert.Equal(t, int64(expectValue), middlewareCounter)
706}
707
708func TestEngineHandleContextPreventsMiddlewareReEntry(t *testing.T) {
709 // given

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
PerformRequestFunction · 0.85
ParamMethod · 0.80
HandleContextMethod · 0.80
UseMethod · 0.65
GETMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected