@@ -16,6 +16,9 @@ import (
16
16
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/config"
17
17
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/gitlabnet/accessverifier"
18
18
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/sshenv"
19
+ "google.golang.org/protobuf/proto"
20
+ "google.golang.org/protobuf/types/known/anypb"
21
+ "google.golang.org/protobuf/types/known/durationpb"
19
22
)
20
23
21
24
func makeHandler (t * testing.T , err error ) func (context.Context , * grpc.ClientConn ) (int32 , error ) {
@@ -88,6 +91,21 @@ func TestUnavailableGitalyErr(t *testing.T) {
88
91
require .Equal (t , err , grpcstatus .Error (grpccodes .Unavailable , "The git server, Gitaly, is not available at this time. Please contact your administrator." ))
89
92
}
90
93
94
+ func TestGitalyLimitErr (t * testing.T ) {
95
+ cmd := NewGitalyCommand (
96
+ newConfig (),
97
+ string (commandargs .UploadPack ),
98
+ & accessverifier.Response {
99
+ Gitaly : accessverifier.Gitaly {Address : "tcp://localhost:9999" },
100
+ },
101
+ )
102
+ limitErr := errWithDetail (t , & pb.LimitError {
103
+ ErrorMessage : "concurrency queue wait time reached" ,
104
+ RetryAfter : durationpb .New (0 )})
105
+ err := cmd .RunGitalyCommand (context .Background (), makeHandler (t , limitErr ))
106
+ require .Equal (t , err , grpcstatus .Error (grpccodes .Unavailable , "GitLab is currently unable to handle this request due to load." ))
107
+ }
108
+
91
109
func TestRunGitalyCommandMetadata (t * testing.T ) {
92
110
tests := []struct {
93
111
name string
@@ -211,3 +229,16 @@ func newConfig() *config.Config {
211
229
cfg .GitalyClient .InitSidechannelRegistry (context .Background ())
212
230
return cfg
213
231
}
232
+
233
+ // errWithDetail adds the given details to the error if it is a gRPC status whose code is not OK.
234
+ func errWithDetail (t * testing.T , detail proto.Message ) error {
235
+ st := grpcstatus .New (grpccodes .Unavailable , "too busy" )
236
+
237
+ proto := st .Proto ()
238
+ marshaled , err := anypb .New (detail )
239
+ require .NoError (t , err )
240
+
241
+ proto .Details = append (proto .Details , marshaled )
242
+
243
+ return grpcstatus .ErrorProto (proto )
244
+ }
0 commit comments