@@ -200,81 +200,83 @@ func TestNoCB(t *testing.T) {
200
200
}
201
201
}
202
202
203
- func TestNoRetry (t * testing.T ) {
204
- atomic .StoreInt32 (& testSTReqCount , - 1 )
205
- // retry config
206
- fp := retry .NewFailurePolicy ()
207
- fp .StopPolicy .CBPolicy .ErrorRate = 0.3
208
- var opts []client.Option
209
- opts = append (opts ,
210
- client .WithFailureRetry (fp ),
211
- client .WithRPCTimeout (20 * time .Millisecond ),
212
- )
213
- cli = getKitexClient (transport .Framed , opts ... )
214
-
215
- ctx , stReq := thriftrpc .CreateSTRequest (context .Background ())
216
- // add a mark to avoid retry
217
- ctx = metainfo .WithPersistentValue (ctx , retry .TransitKey , strconv .Itoa (1 ))
218
- ctx = metainfo .WithValue (ctx , skipCounterSleepKey , "1" ) // do not sleep by global variable
203
+ func TestRetry (t * testing.T ) {
204
+ t .Run ("TestNoRetry" , func (t * testing.T ) {
205
+ atomic .StoreInt32 (& testSTReqCount , - 1 )
206
+ // retry config
207
+ fp := retry .NewFailurePolicy ()
208
+ fp .StopPolicy .CBPolicy .ErrorRate = 0.3
209
+ var opts []client.Option
210
+ opts = append (opts ,
211
+ client .WithFailureRetry (fp ),
212
+ client .WithRPCTimeout (20 * time .Millisecond ),
213
+ )
214
+ cli = getKitexClient (transport .Framed , opts ... )
219
215
220
- for i := 0 ; i < 250 ; i ++ {
221
- reqCtx := ctx
222
- if i % 10 == 0 {
223
- reqCtx = metainfo .WithValue (ctx , sleepTimeMsKey , "100" )
216
+ ctx , stReq := thriftrpc .CreateSTRequest (context .Background ())
217
+ // add a mark to avoid retry
218
+ ctx = metainfo .WithPersistentValue (ctx , retry .TransitKey , strconv .Itoa (1 ))
219
+ ctx = metainfo .WithValue (ctx , skipCounterSleepKey , "1" ) // do not sleep by global variable
220
+
221
+ for i := 0 ; i < 250 ; i ++ {
222
+ reqCtx := ctx
223
+ if i % 10 == 0 {
224
+ reqCtx = metainfo .WithValue (ctx , sleepTimeMsKey , "100" )
225
+ }
226
+ stResp , err := cli .TestSTReq (reqCtx , stReq )
227
+ if i % 10 == 0 {
228
+ test .Assert (t , err != nil )
229
+ test .Assert (t , strings .Contains (err .Error (), retryChainStopStr ), err )
230
+ } else {
231
+ test .Assert (t , err == nil , err , i )
232
+ test .Assert (t , stReq .Str == stResp .Str )
233
+ }
224
234
}
225
- stResp , err := cli .TestSTReq (reqCtx , stReq )
226
- if i % 10 == 0 {
227
- test .Assert (t , err != nil )
228
- test .Assert (t , strings .Contains (err .Error (), retryChainStopStr ), err )
229
- } else {
230
- test .Assert (t , err == nil , err , i )
235
+ })
236
+
237
+ t .Run ("TestBackupRequest" , func (t * testing.T ) {
238
+ atomic .StoreInt32 (& testSTReqCount , - 1 )
239
+ // retry config
240
+ bp := retry .NewBackupPolicy (5 )
241
+ var opts []client.Option
242
+ opts = append (opts ,
243
+ client .WithBackupRequest (bp ),
244
+ client .WithRPCTimeout (40 * time .Millisecond ),
245
+ )
246
+ cli = getKitexClient (transport .Framed , opts ... )
247
+ for i := 0 ; i < 300 ; i ++ {
248
+ ctx , stReq := thriftrpc .CreateSTRequest (context .Background ())
249
+ stReq .Int64 = int64 (i )
250
+ stResp , err := cli .TestSTReq (ctx , stReq )
251
+ test .Assert (t , err == nil , err , i , testSTReqCount )
231
252
test .Assert (t , stReq .Str == stResp .Str )
232
253
}
233
- }
234
- }
235
-
236
- func TestBackupRequest (t * testing.T ) {
237
- atomic .StoreInt32 (& testSTReqCount , - 1 )
238
- // retry config
239
- bp := retry .NewBackupPolicy (5 )
240
- var opts []client.Option
241
- opts = append (opts ,
242
- client .WithBackupRequest (bp ),
243
- client .WithRPCTimeout (40 * time .Millisecond ),
244
- )
245
- cli = getKitexClient (transport .Framed , opts ... )
246
- for i := 0 ; i < 300 ; i ++ {
247
- ctx , stReq := thriftrpc .CreateSTRequest (context .Background ())
248
- stReq .Int64 = int64 (i )
249
- stResp , err := cli .TestSTReq (ctx , stReq )
250
- test .Assert (t , err == nil , err , i , testSTReqCount )
251
- test .Assert (t , stReq .Str == stResp .Str )
252
- }
253
- }
254
+ })
254
255
255
- func TestServiceCB (t * testing.T ) {
256
- atomic .StoreInt32 (& circuitBreakTestCount , - 1 )
257
- // retry config
258
- fp := retry .NewFailurePolicy ()
259
- var opts []client.Option
260
- opts = append (opts , client .WithFailureRetry (fp ))
261
- opts = append (opts , client .WithRPCTimeout (50 * time .Millisecond ))
262
- opts = append (opts , client .WithCircuitBreaker (circuitbreak .NewCBSuite (genCBKey )))
263
- cli = getKitexClient (transport .TTHeader , opts ... )
256
+ t . Run ( " TestServiceCB" , func (t * testing.T ) {
257
+ atomic .StoreInt32 (& circuitBreakTestCount , - 1 )
258
+ // retry config
259
+ fp := retry .NewFailurePolicy ()
260
+ var opts []client.Option
261
+ opts = append (opts , client .WithFailureRetry (fp ))
262
+ opts = append (opts , client .WithRPCTimeout (50 * time .Millisecond ))
263
+ opts = append (opts , client .WithCircuitBreaker (circuitbreak .NewCBSuite (genCBKey )))
264
+ cli = getKitexClient (transport .TTHeader , opts ... )
264
265
265
- ctx , stReq := thriftrpc .CreateSTRequest (context .Background ())
266
- cbCount := 0
267
- for i := 0 ; i < 300 ; i ++ {
268
- stResp , err := cli .CircuitBreakTest (ctx , stReq )
269
- if err != nil {
270
- test .Assert (t , strings .Contains (err .Error (), "retry circuit break" ) ||
271
- strings .Contains (err .Error (), "service circuitbreak" ), err , i )
272
- cbCount ++
273
- } else {
274
- test .Assert (t , stReq .Str == stResp .Str )
266
+ ctx , stReq := thriftrpc .CreateSTRequest (context .Background ())
267
+ cbCount := 0
268
+ for i := 0 ; i < 300 ; i ++ {
269
+ stResp , err := cli .CircuitBreakTest (ctx , stReq )
270
+ if err != nil {
271
+ test .Assert (t , strings .Contains (err .Error (), "retry circuit break" ) ||
272
+ strings .Contains (err .Error (), "service circuitbreak" ), err , i )
273
+ cbCount ++
274
+ } else {
275
+ test .Assert (t , stReq .Str == stResp .Str )
276
+ }
275
277
}
276
- }
277
- test . Assert ( t , cbCount == 200 , cbCount )
278
+ test . Assert ( t , cbCount == 200 , cbCount )
279
+ } )
278
280
}
279
281
280
282
func TestRetryWithSpecifiedResultRetry (t * testing.T ) {
0 commit comments