@@ -2,9 +2,13 @@ package log
22
33import (
44 "context"
5+ "strconv"
56 "testing"
7+ "time"
68
79 "github.com/stretchr/testify/require"
10+
11+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest"
812)
913
1014func TestLevelFromContext (t * testing.T ) {
@@ -54,3 +58,35 @@ func TestNamesFromContext(t *testing.T) {
5458 })
5559 }
5660}
61+
62+ func TestWithNamesRaceRegression (t * testing.T ) {
63+ count := 100
64+ xtest .TestManyTimes (t , func (t testing.TB ) {
65+ ctx := WithNames (context .Background (), "test" )
66+ ctx = WithNames (ctx , "test" )
67+ ctx = WithNames (ctx , "test" )
68+ res := make ([]context.Context , count )
69+
70+ start := make (chan bool )
71+ finished := make (chan bool )
72+ for i := 0 ; i < count ; i ++ {
73+ go func (index int ) {
74+ <- start
75+ res [index ] = WithNames (ctx , strconv .Itoa (index ))
76+ finished <- true
77+ }(i )
78+ }
79+
80+ time .Sleep (time .Microsecond )
81+ close (start )
82+
83+ for i := 0 ; i < count ; i ++ {
84+ <- finished
85+ }
86+
87+ for i := 0 ; i < count ; i ++ {
88+ expected := []string {"test" , "test" , "test" , strconv .Itoa (i )}
89+ require .Equal (t , expected , NamesFromContext (res [i ]))
90+ }
91+ })
92+ }
0 commit comments