MCPcopy Index your code
hub / github.com/labstack/echo / TestConcurrentRouter_ConcurrentWrites

Function TestConcurrentRouter_ConcurrentWrites

router_concurrent_test.go:95–139  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func TestConcurrentRouter_ConcurrentWrites(t *testing.T) {
96 router := NewConcurrentRouter(NewRouter(RouterConfig{}))
97
98 _, _ = router.Add(Route{Method: http.MethodGet, Path: "/initial1", Handler: handlerFunc})
99 _, _ = router.Add(Route{Method: http.MethodGet, Path: "/initial2", Handler: handlerFunc})
100
101 // Launch 5 goroutines, each adds 10 unique routes
102 var wg sync.WaitGroup
103 var addCount atomic.Int64
104
105 numGoroutines := 5
106 addsPerGoroutine := 10
107
108 for i := range numGoroutines {
109 wg.Add(1)
110 go func(goroutineID int) {
111 defer wg.Done()
112
113 for j := range addsPerGoroutine {
114 path := fmt.Sprintf("/route-g%d-n%d", goroutineID, j)
115 _, err := router.Add(Route{
116 Method: http.MethodGet,
117 Path: path,
118 Handler: handlerFunc,
119 })
120 if err == nil {
121 addCount.Add(1)
122 }
123 }
124 }(i)
125 }
126
127 wg.Wait()
128
129 // Verify final route count
130 expectedAdds := int64(numGoroutines * addsPerGoroutine)
131 assert.Equal(t, expectedAdds, addCount.Load(), "all Add() calls should succeed")
132
133 expectedTotal := 2 + int(expectedAdds) // 2 initial + 50 added
134 assert.Len(t, router.Routes(), expectedTotal, "route count mismatch")
135
136 // Verify all routes are accessible
137 allRoutes := router.Routes()
138 assert.Len(t, allRoutes, expectedTotal)
139}
140
141func TestConcurrentRouter_ConcurrentReadWrite(t *testing.T) {
142 router := NewConcurrentRouter(NewRouter(RouterConfig{}))

Callers

nothing calls this directly

Calls 4

NewConcurrentRouterFunction · 0.85
NewRouterFunction · 0.85
AddMethod · 0.65
RoutesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…