@@ -3337,74 +3337,55 @@ func TestRetryReadStallEmulated(t *testing.T) {
33373337
33383338func TestGRPCRetryReadStallEmulated (t * testing.T ) {
33393339 checkEmulatorEnvironment (t )
3340+ t .Run ("ReadObject" , func (t * testing.T ) {
3341+ ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
3342+ defer cancel ()
33403343
3341- tests := []struct {
3342- name string
3343- bidiReads bool
3344- }{
3345- {
3346- name : "ReadObject" ,
3347- bidiReads : false ,
3348- },
3349- {
3350- name : "BidiReadObject" ,
3351- bidiReads : true ,
3352- },
3353- }
3354-
3355- for _ , tt := range tests {
3356- t .Run (tt .name , func (t * testing.T ) {
3357- ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
3358- defer cancel ()
3344+ opts := []option.ClientOption {
3345+ experimental .WithReadStallTimeout (
3346+ & experimental.ReadStallTimeoutConfig {
3347+ TargetPercentile : 0.99 ,
3348+ Min : 250 * time .Millisecond ,
3349+ }),
3350+ }
33593351
3360- opts := []option.ClientOption {
3361- experimental .WithReadStallTimeout (
3362- & experimental.ReadStallTimeoutConfig {
3363- TargetPercentile : 0.99 ,
3364- Min : 250 * time .Millisecond ,
3365- }),
3366- }
3367- if tt .bidiReads {
3368- opts = append (opts , experimental .WithGRPCBidiReads ())
3369- }
3352+ client , err := NewGRPCClient (ctx , opts ... )
3353+ if err != nil {
3354+ t .Fatalf ("storage.NewGRPCClient: %v" , err )
3355+ }
3356+ defer client .Close ()
3357+ client .SetRetry (WithBackoff (gax.Backoff {Initial : 10 * time .Millisecond }))
33703358
3371- client , err := NewGRPCClient (ctx , opts ... )
3372- if err != nil {
3373- t .Fatalf ("storage.NewGRPCClient: %v" , err )
3374- }
3375- defer client .Close ()
3376- client .SetRetry (WithBackoff (gax.Backoff {Initial : 10 * time .Millisecond }))
3359+ project := "fake-project"
3360+ bucket := fmt .Sprintf ("grpc-bucket-%d" , time .Now ().Nanosecond ())
3361+ if err := client .Bucket (bucket ).Create (ctx , project , nil ); err != nil {
3362+ t .Fatalf ("client.Bucket.Create: %v" , err )
3363+ }
33773364
3378- project := "fake-project"
3379- bucket := fmt .Sprintf ("grpc-bucket-%d" , time .Now ().Nanosecond ())
3380- if err := client .Bucket (bucket ).Create (ctx , project , nil ); err != nil {
3381- t .Fatalf ("client.Bucket.Create: %v" , err )
3382- }
3365+ name , _ , _ , err := createObjectWithContent (ctx , bucket , randomBytes3MiB )
3366+ if err != nil {
3367+ t .Fatalf ("createObject: %v" , err )
3368+ }
33833369
3384- name , _ , _ , err := createObjectWithContent (ctx , bucket , randomBytes3MiB )
3385- if err != nil {
3386- t .Fatalf ("createObject: %v" , err )
3387- }
3370+ instructions := map [string ][]string {"storage.objects.get" : {"stall-for-10s-after-0K" }}
3371+ testID := createRetryTest (t , client .tc , instructions )
33883372
3389- instructions := map [string ][]string {"storage.objects.get" : {"stall-for-10s-after-0K" }}
3390- testID := createRetryTest (t , client .tc , instructions )
3373+ testCtx := callctx .SetHeaders (ctx , "x-retry-test-id" , testID )
33913374
3392- ctx = callctx .SetHeaders (ctx , "x-retry-test-id" , testID )
3393- r , err := client .Bucket (bucket ).Object (name ).NewReader (ctx )
3394- if err != nil {
3395- t .Fatalf ("NewReader: %v" , err )
3396- }
3397- defer r .Close ()
3375+ r , err := client .Bucket (bucket ).Object (name ).NewReader (testCtx )
3376+ if err != nil {
3377+ t .Fatalf ("NewReader: %v" , err )
3378+ }
3379+ defer r .Close ()
33983380
3399- buf := & bytes.Buffer {}
3400- if _ , err := io .Copy (buf , r ); err != nil {
3401- t .Fatalf ("io.Copy: %v" , err )
3402- }
3403- if ! bytes .Equal (buf .Bytes (), randomBytes3MiB ) {
3404- t .Errorf ("content does not match, got len %v, want len %v" , buf .Len (), len (randomBytes3MiB ))
3405- }
3406- })
3407- }
3381+ buf := & bytes.Buffer {}
3382+ if _ , err := io .Copy (buf , r ); err != nil {
3383+ t .Fatalf ("io.Copy: %v" , err )
3384+ }
3385+ if ! bytes .Equal (buf .Bytes (), randomBytes3MiB ) {
3386+ t .Errorf ("content does not match, got len %v, want len %v" , buf .Len (), len (randomBytes3MiB ))
3387+ }
3388+ })
34083389}
34093390
34103391func TestWriterChunkTransferTimeoutEmulated (t * testing.T ) {
0 commit comments