mirror of
https://github.com/gin-gonic/gin.git
synced 2026-11-23 11:33:37 +08:00
Merge branch 'master' into fix/tree-grow-skipped-nodes
This commit is contained in:
commit
742c541a91
@ -132,9 +132,8 @@ func (c *Context) Copy() *Context {
|
||||
cp.handlers = nil
|
||||
cp.fullPath = c.fullPath
|
||||
|
||||
cKeys := c.Keys
|
||||
c.mu.RLock()
|
||||
cp.Keys = maps.Clone(cKeys)
|
||||
cp.Keys = maps.Clone(c.Keys)
|
||||
c.mu.RUnlock()
|
||||
|
||||
cParams := c.Params
|
||||
|
||||
@ -709,6 +709,30 @@ func TestContextGetStringMapStringSlice(t *testing.T) {
|
||||
assert.Equal(t, []string{"foo"}, c.GetStringMapStringSlice("map")["foo"])
|
||||
}
|
||||
|
||||
func TestCopyConcurrentWithSet(t *testing.T) {
|
||||
c := &Context{}
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for i := 0; i < 100; i++ {
|
||||
c.Set(i, i)
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for i := 0; i < 100; i++ {
|
||||
cp := c.Copy()
|
||||
for k, v := range cp.Keys {
|
||||
if k != v {
|
||||
t.Errorf("copied key %v = %v, want %v", k, v, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestContextCopy(t *testing.T) {
|
||||
c, _ := CreateTestContext(httptest.NewRecorder())
|
||||
c.index = 2
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user