@@ -19,6 +19,7 @@ import (
1919 "github.com/sourcegraph/sourcegraph/internal/api"
2020 "github.com/sourcegraph/sourcegraph/internal/database/dbmocks"
2121 "github.com/sourcegraph/sourcegraph/internal/extsvc/github"
22+ "github.com/sourcegraph/sourcegraph/internal/ratelimit"
2223 "github.com/sourcegraph/sourcegraph/internal/repoupdater/protocol"
2324 "github.com/sourcegraph/sourcegraph/lib/errors"
2425
@@ -622,6 +623,13 @@ func TestExternalServices(t *testing.T) {
622623 users .GetByCurrentAuthUserFunc .SetDefaultReturn (& types.User {SiteAdmin : true }, nil )
623624
624625 externalServices := dbmocks .NewMockExternalServiceStore ()
626+ ess := []* types.ExternalService {
627+ {ID : 1 , Config : extsvc .NewEmptyConfig ()},
628+ {ID : 2 , Config : extsvc .NewEmptyConfig (), Kind : extsvc .KindGitHub },
629+ {ID : 3 , Config : extsvc .NewEmptyConfig (), Kind : extsvc .KindGitHub },
630+ {ID : 4 , Config : extsvc .NewEmptyConfig (), Kind : extsvc .KindAWSCodeCommit },
631+ {ID : 5 , Config : extsvc .NewEmptyConfig (), Kind : extsvc .KindGerrit },
632+ }
625633 externalServices .ListFunc .SetDefaultHook (func (_ context.Context , opt database.ExternalServicesListOptions ) ([]* types.ExternalService , error ) {
626634 if opt .AfterID > 0 || opt .RepoID == 42 {
627635 return []* types.ExternalService {
@@ -630,18 +638,20 @@ func TestExternalServices(t *testing.T) {
630638 }, nil
631639 }
632640
633- ess := []* types.ExternalService {
634- {ID : 1 , Config : extsvc .NewEmptyConfig ()},
635- {ID : 2 , Config : extsvc .NewEmptyConfig (), Kind : extsvc .KindGitHub },
636- {ID : 3 , Config : extsvc .NewEmptyConfig (), Kind : extsvc .KindGitHub },
637- {ID : 4 , Config : extsvc .NewEmptyConfig (), Kind : extsvc .KindAWSCodeCommit },
638- {ID : 5 , Config : extsvc .NewEmptyConfig (), Kind : extsvc .KindGerrit },
639- }
640641 if opt .LimitOffset != nil {
641642 return ess [:opt .LimitOffset .Limit ], nil
642643 }
643644 return ess , nil
644645 })
646+
647+ // Set up rate limits
648+ ctx := context .Background ()
649+ ratelimit .SetupForTest (t )
650+ for _ , es := range ess {
651+ rl := ratelimit .NewGlobalRateLimiter (logtest .NoOp (t ), es .URN ())
652+ rl .SetTokenBucketConfig (ctx , 10 , time .Hour )
653+ }
654+
645655 externalServices .CountFunc .SetDefaultHook (func (ctx context.Context , opt database.ExternalServicesListOptions ) (int , error ) {
646656 if opt .AfterID > 0 {
647657 return 1 , nil
@@ -698,6 +708,90 @@ func TestExternalServices(t *testing.T) {
698708 }
699709 ` ,
700710 },
711+ {
712+ Schema : mustParseGraphQLSchema (t , db ),
713+ Label : "Read with rate limiter state" ,
714+ Query : `
715+ {
716+ externalServices {
717+ nodes {
718+ id
719+ rateLimiterState {
720+ burst
721+ currentCapacity
722+ infinite
723+ interval
724+ lastReplenishment
725+ limit
726+ }
727+ }
728+ }
729+ }
730+ ` ,
731+ ExpectedResult : `
732+ {
733+ "externalServices": {
734+ "nodes": [
735+ {
736+ "id":"RXh0ZXJuYWxTZXJ2aWNlOjE=",
737+ "rateLimiterState": {
738+ "burst": 10,
739+ "currentCapacity": 0,
740+ "infinite": false,
741+ "interval": 3600,
742+ "lastReplenishment": "1970-01-01T00:00:00Z",
743+ "limit": 10
744+ }
745+ },
746+ {
747+ "id":"RXh0ZXJuYWxTZXJ2aWNlOjI=",
748+ "rateLimiterState": {
749+ "burst": 10,
750+ "currentCapacity": 0,
751+ "infinite": false,
752+ "interval": 3600,
753+ "lastReplenishment": "1970-01-01T00:00:00Z",
754+ "limit": 10
755+ }
756+ },
757+ {
758+ "id":"RXh0ZXJuYWxTZXJ2aWNlOjM=",
759+ "rateLimiterState": {
760+ "burst": 10,
761+ "currentCapacity": 0,
762+ "infinite": false,
763+ "interval": 3600,
764+ "lastReplenishment": "1970-01-01T00:00:00Z",
765+ "limit": 10
766+ }
767+ },
768+ {
769+ "id":"RXh0ZXJuYWxTZXJ2aWNlOjQ=",
770+ "rateLimiterState": {
771+ "burst": 10,
772+ "currentCapacity": 0,
773+ "infinite": false,
774+ "interval": 3600,
775+ "lastReplenishment": "1970-01-01T00:00:00Z",
776+ "limit": 10
777+ }
778+ },
779+ {
780+ "id":"RXh0ZXJuYWxTZXJ2aWNlOjU=",
781+ "rateLimiterState": {
782+ "burst": 10,
783+ "currentCapacity": 0,
784+ "infinite": false,
785+ "interval": 3600,
786+ "lastReplenishment": "1970-01-01T00:00:00Z",
787+ "limit": 10
788+ }
789+ }
790+ ]
791+ }
792+ }
793+ ` ,
794+ },
701795 {
702796 Schema : mustParseGraphQLSchema (t , db ),
703797 Label : "Read all external services for a given repo" ,
0 commit comments