(t *testing.T)
| 669 | } |
| 670 | |
| 671 | func 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 | |
| 708 | func TestEngineHandleContextPreventsMiddlewareReEntry(t *testing.T) { |
| 709 | // given |
nothing calls this directly
no test coverage detected