11package async
22
33import (
4+ "maps"
45 "runtime"
56 "strconv"
67 "sync"
@@ -12,9 +13,12 @@ import (
1213)
1314
1415func TestMap_Clear (t * testing.T ) {
16+ t .Parallel ()
17+
1518 tests := prepareTestMaps ()
1619 for _ , tt := range tests {
1720 t .Run (tt .name , func (t * testing.T ) {
21+ t .Parallel ()
1822 tt .m .Clear ()
1923 assert .Equal (t , tt .m .Size (), 0 )
2024 tt .m .Put (1 , util .Ptr ("a" ))
@@ -24,9 +28,12 @@ func TestMap_Clear(t *testing.T) {
2428}
2529
2630func TestMap_ComputeIfAbsent (t * testing.T ) {
31+ t .Parallel ()
32+
2733 tests := prepareTestMaps ()
2834 for _ , tt := range tests {
2935 t .Run (tt .name , func (t * testing.T ) {
36+ t .Parallel ()
3037 assert .Equal (
3138 t ,
3239 tt .m .ComputeIfAbsent (4 , func (_ int ) * string { return util .Ptr ("d" ) }),
@@ -44,39 +51,51 @@ func TestMap_ComputeIfAbsent(t *testing.T) {
4451}
4552
4653func TestMap_ContainsKey (t * testing.T ) {
54+ t .Parallel ()
55+
4756 tests := prepareTestMaps ()
4857 for _ , tt := range tests {
4958 t .Run (tt .name , func (t * testing.T ) {
59+ t .Parallel ()
5060 assert .Equal (t , tt .m .ContainsKey (3 ), true )
5161 assert .Equal (t , tt .m .ContainsKey (4 ), false )
5262 })
5363 }
5464}
5565
5666func TestMap_Get (t * testing.T ) {
67+ t .Parallel ()
68+
5769 tests := prepareTestMaps ()
5870 for _ , tt := range tests {
5971 t .Run (tt .name , func (t * testing.T ) {
72+ t .Parallel ()
6073 assert .Equal (t , tt .m .Get (1 ), util .Ptr ("a" ))
6174 assert .IsNil (t , tt .m .Get (4 ))
6275 })
6376 }
6477}
6578
6679func TestMap_GetOrDefault (t * testing.T ) {
80+ t .Parallel ()
81+
6782 tests := prepareTestMaps ()
6883 for _ , tt := range tests {
6984 t .Run (tt .name , func (t * testing.T ) {
85+ t .Parallel ()
7086 assert .Equal (t , tt .m .GetOrDefault (1 , util .Ptr ("e" )), util .Ptr ("a" ))
7187 assert .Equal (t , tt .m .GetOrDefault (5 , util .Ptr ("e" )), util .Ptr ("e" ))
7288 })
7389 }
7490}
7591
7692func TestMap_IsEmpty (t * testing.T ) {
93+ t .Parallel ()
94+
7795 tests := prepareTestMaps ()
7896 for _ , tt := range tests {
7997 t .Run (tt .name , func (t * testing.T ) {
98+ t .Parallel ()
8099 assert .Equal (t , tt .m .IsEmpty (), false )
81100 tt .m .Clear ()
82101 assert .Equal (t , tt .m .IsEmpty (), true )
@@ -85,9 +104,12 @@ func TestMap_IsEmpty(t *testing.T) {
85104}
86105
87106func TestMap_KeySet (t * testing.T ) {
107+ t .Parallel ()
108+
88109 tests := prepareTestMaps ()
89110 for _ , tt := range tests {
90111 t .Run (tt .name , func (t * testing.T ) {
112+ t .Parallel ()
91113 assert .ElementsMatch (t , tt .m .KeySet (), []int {1 , 2 , 3 })
92114 tt .m .Put (4 , util .Ptr ("d" ))
93115 assert .ElementsMatch (t , tt .m .KeySet (), []int {1 , 2 , 3 , 4 })
@@ -96,9 +118,12 @@ func TestMap_KeySet(t *testing.T) {
96118}
97119
98120func TestMap_Put (t * testing.T ) {
121+ t .Parallel ()
122+
99123 tests := prepareTestMaps ()
100124 for _ , tt := range tests {
101125 t .Run (tt .name , func (t * testing.T ) {
126+ t .Parallel ()
102127 assert .Equal (t , tt .m .Size (), 3 )
103128 tt .m .Put (4 , util .Ptr ("d" ))
104129 assert .Equal (t , tt .m .Size (), 4 )
@@ -111,9 +136,12 @@ func TestMap_Put(t *testing.T) {
111136}
112137
113138func TestMap_Remove (t * testing.T ) {
139+ t .Parallel ()
140+
114141 tests := prepareTestMaps ()
115142 for _ , tt := range tests {
116143 t .Run (tt .name , func (t * testing.T ) {
144+ t .Parallel ()
117145 assert .Equal (t , tt .m .Remove (3 ), util .Ptr ("c" ))
118146 assert .Equal (t , tt .m .Size (), 2 )
119147 assert .IsNil (t , tt .m .Remove (5 ))
@@ -123,18 +151,24 @@ func TestMap_Remove(t *testing.T) {
123151}
124152
125153func TestMap_Size (t * testing.T ) {
154+ t .Parallel ()
155+
126156 tests := prepareTestMaps ()
127157 for _ , tt := range tests {
128158 t .Run (tt .name , func (t * testing.T ) {
159+ t .Parallel ()
129160 assert .Equal (t , tt .m .Size (), 3 )
130161 })
131162 }
132163}
133164
134165func TestMap_Values (t * testing.T ) {
166+ t .Parallel ()
167+
135168 tests := prepareTestMaps ()
136169 for _ , tt := range tests {
137170 t .Run (tt .name , func (t * testing.T ) {
171+ t .Parallel ()
138172 assert .ElementsMatch (
139173 t ,
140174 tt .m .Values (),
@@ -150,7 +184,38 @@ func TestMap_Values(t *testing.T) {
150184 }
151185}
152186
187+ func TestMap_All (t * testing.T ) {
188+ t .Parallel ()
189+
190+ tests := prepareTestMaps ()
191+ for _ , tt := range tests {
192+ t .Run (tt .name , func (t * testing.T ) {
193+ t .Parallel ()
194+ // collect all key-value pairs from the iterator
195+ collected := maps .Collect (tt .m .All ())
196+
197+ // verify we got all 3 expected pairs
198+ expected := map [int ]* string {
199+ 1 : util .Ptr ("a" ),
200+ 2 : util .Ptr ("b" ),
201+ 3 : util .Ptr ("c" ),
202+ }
203+ assert .Equal (t , collected , expected )
204+
205+ // add a new entry and verify it appears in the iterator
206+ tt .m .Put (4 , util .Ptr ("d" ))
207+ collected = maps .Collect (tt .m .All ())
208+
209+ // verify we now have 4 pairs
210+ expected [4 ] = util .Ptr ("d" )
211+ assert .Equal (t , collected , expected )
212+ })
213+ }
214+ }
215+
153216func TestShardedMap_ConstructorArguments (t * testing.T ) {
217+ t .Parallel ()
218+
154219 assert .PanicMsgContains (t , func () {
155220 NewShardedMap [int , string ](0 )
156221 }, "nonpositive shards" )
@@ -167,6 +232,8 @@ func TestShardedMap_ConstructorArguments(t *testing.T) {
167232}
168233
169234func TestConcurrentMap_MemoryLeaks (t * testing.T ) {
235+ t .Parallel ()
236+
170237 var statsBefore runtime.MemStats
171238 runtime .ReadMemStats (& statsBefore )
172239
0 commit comments