@@ -16,6 +16,9 @@ import (
1616 "gitlab.com/gitlab-org/gitlab-shell/v14/internal/config"
1717 "gitlab.com/gitlab-org/gitlab-shell/v14/internal/gitlabnet/accessverifier"
1818 "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"
1922)
2023
2124func makeHandler (t * testing.T , err error ) func (context.Context , * grpc.ClientConn ) (int32 , error ) {
@@ -88,6 +91,21 @@ func TestUnavailableGitalyErr(t *testing.T) {
8891 require .Equal (t , err , grpcstatus .Error (grpccodes .Unavailable , "The git server, Gitaly, is not available at this time. Please contact your administrator." ))
8992}
9093
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+
91109func TestRunGitalyCommandMetadata (t * testing.T ) {
92110 tests := []struct {
93111 name string
@@ -211,3 +229,16 @@ func newConfig() *config.Config {
211229 cfg .GitalyClient .InitSidechannelRegistry (context .Background ())
212230 return cfg
213231}
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