mirror of
https://github.com/gin-gonic/gin.git
synced 2026-09-04 14:49:27 +08:00
Merge c58089110a51c9e0fa585c5a1c962ca989251359 into dcaa4296d111981ffb31ac3eba90bb63e1eb5ab9
This commit is contained in:
commit
ba0393f7dc
@ -132,9 +132,8 @@ func (c *Context) Copy() *Context {
|
|||||||
cp.handlers = nil
|
cp.handlers = nil
|
||||||
cp.fullPath = c.fullPath
|
cp.fullPath = c.fullPath
|
||||||
|
|
||||||
cKeys := c.Keys
|
|
||||||
c.mu.RLock()
|
c.mu.RLock()
|
||||||
cp.Keys = maps.Clone(cKeys)
|
cp.Keys = maps.Clone(c.Keys)
|
||||||
c.mu.RUnlock()
|
c.mu.RUnlock()
|
||||||
|
|
||||||
cParams := c.Params
|
cParams := c.Params
|
||||||
|
|||||||
@ -776,6 +776,29 @@ func TestContextCopyNilErrorsAndAccepted(t *testing.T) {
|
|||||||
assert.Nil(t, cp.Accepted)
|
assert.Nil(t, cp.Accepted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContextCopyRace(t *testing.T) {
|
||||||
|
c := &Context{}
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(2)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
for range 1000 {
|
||||||
|
c.Set("foo", "bar")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
for range 1000 {
|
||||||
|
c.Copy()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
func TestContextHandlerName(t *testing.T) {
|
func TestContextHandlerName(t *testing.T) {
|
||||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||||
c.handlers = HandlersChain{func(c *Context) {}, handlerNameTest}
|
c.handlers = HandlersChain{func(c *Context) {}, handlerNameTest}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user