@@ -318,13 +318,16 @@ describe('create runner', () => {
318318 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
319319 capacityType : 'spot' ,
320320 type : 'Org' ,
321+ scaleErrors : [ ] ,
322+ source : 'scale-up-lambda' ,
321323 } ;
322324
323325 const defaultExpectedFleetRequestValues : ExpectedFleetRequestValues = {
324326 type : 'Org' ,
325327 capacityType : 'spot' ,
326328 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
327329 totalTargetCapacity : 1 ,
330+ source : 'scale-up-lambda' ,
328331 } ;
329332
330333 beforeEach ( ( ) => {
@@ -365,6 +368,25 @@ describe('create runner', () => {
365368 } ) ;
366369 } ) ;
367370
371+ it ( 'calls create fleet of multiple instances with pool-lambda source when specified' , async ( ) => {
372+ const instances = [ { InstanceIds : [ 'i-1234' , 'i-5678' , 'i-9012' ] } ] ;
373+
374+ mockEC2Client . on ( CreateFleetCommand ) . resolves ( { Instances : instances } ) ;
375+
376+ await createRunner ( {
377+ ...createRunnerConfig ( { ...defaultRunnerConfig , source : 'pool-lambda' } ) ,
378+ numberOfRunners : 3 ,
379+ } ) ;
380+
381+ expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
382+ ...expectedCreateFleetRequest ( {
383+ ...defaultExpectedFleetRequestValues ,
384+ totalTargetCapacity : 3 ,
385+ source : 'pool-lambda' ,
386+ } ) ,
387+ } ) ;
388+ } ) ;
389+
368390 it ( 'calls create fleet of 1 instance with the on-demand capacity' , async ( ) => {
369391 await createRunner ( createRunnerConfig ( { ...defaultRunnerConfig , capacityType : 'on-demand' } ) ) ;
370392 expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
@@ -425,6 +447,28 @@ describe('create runner', () => {
425447 } ) ,
426448 } ) ;
427449 } ) ;
450+
451+ it ( 'calls create fleet with source set to scale-up-lambda when source is specified' , async ( ) => {
452+ await createRunner ( createRunnerConfig ( { ...defaultRunnerConfig , source : 'scale-up-lambda' } ) ) ;
453+
454+ expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
455+ ...expectedCreateFleetRequest ( {
456+ ...defaultExpectedFleetRequestValues ,
457+ source : 'scale-up-lambda' ,
458+ } ) ,
459+ } ) ;
460+ } ) ;
461+
462+ it ( 'calls create fleet with source set to pool-lambda when source is specified' , async ( ) => {
463+ await createRunner ( createRunnerConfig ( { ...defaultRunnerConfig , source : 'pool-lambda' } ) ) ;
464+
465+ expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
466+ ...expectedCreateFleetRequest ( {
467+ ...defaultExpectedFleetRequestValues ,
468+ source : 'pool-lambda' ,
469+ } ) ,
470+ } ) ;
471+ } ) ;
428472} ) ;
429473
430474describe ( 'create runner with errors' , ( ) => {
@@ -433,12 +477,14 @@ describe('create runner with errors', () => {
433477 capacityType : 'spot' ,
434478 type : 'Repo' ,
435479 scaleErrors : [ 'UnfulfillableCapacity' , 'MaxSpotInstanceCountExceeded' ] ,
480+ source : 'scale-up-lambda' ,
436481 } ;
437482 const defaultExpectedFleetRequestValues : ExpectedFleetRequestValues = {
438483 type : 'Repo' ,
439484 capacityType : 'spot' ,
440485 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
441486 totalTargetCapacity : 1 ,
487+ source : 'scale-up-lambda' ,
442488 } ;
443489 beforeEach ( ( ) => {
444490 vi . clearAllMocks ( ) ;
@@ -546,12 +592,15 @@ describe('create runner with errors fail over to OnDemand', () => {
546592 capacityType : 'spot' ,
547593 type : 'Repo' ,
548594 onDemandFailoverOnError : [ 'InsufficientInstanceCapacity' ] ,
595+ scaleErrors : [ ] ,
596+ source : 'scale-up-lambda' ,
549597 } ;
550598 const defaultExpectedFleetRequestValues : ExpectedFleetRequestValues = {
551599 type : 'Repo' ,
552600 capacityType : 'spot' ,
553601 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
554602 totalTargetCapacity : 1 ,
603+ source : 'scale-up-lambda' ,
555604 } ;
556605 beforeEach ( ( ) => {
557606 vi . clearAllMocks ( ) ;
@@ -704,6 +753,7 @@ interface RunnerConfig {
704753 tracingEnabled ?: boolean ;
705754 onDemandFailoverOnError ?: string [ ] ;
706755 scaleErrors : string [ ] ;
756+ source : 'scale-up-lambda' | 'pool-lambda' ;
707757}
708758
709759function createRunnerConfig ( runnerConfig : RunnerConfig ) : RunnerInputParameters {
@@ -724,6 +774,7 @@ function createRunnerConfig(runnerConfig: RunnerConfig): RunnerInputParameters {
724774 tracingEnabled : runnerConfig . tracingEnabled ,
725775 onDemandFailoverOnError : runnerConfig . onDemandFailoverOnError ,
726776 scaleErrors : runnerConfig . scaleErrors ,
777+ source : runnerConfig . source ,
727778 } ;
728779}
729780
@@ -735,14 +786,15 @@ interface ExpectedFleetRequestValues {
735786 totalTargetCapacity : number ;
736787 imageId ?: string ;
737788 tracingEnabled ?: boolean ;
789+ source : 'scale-up-lambda' | 'pool-lambda' ;
738790}
739791
740792function expectedCreateFleetRequest ( expectedValues : ExpectedFleetRequestValues ) : CreateFleetCommandInput {
741793 const tags = [
742794 { Key : 'ghr:Application' , Value : 'github-action-runner' } ,
743795 {
744796 Key : 'ghr:created_by' ,
745- Value : expectedValues . totalTargetCapacity > 1 ? 'pool-lambda' : 'scale-up-lambda' ,
797+ Value : expectedValues . source ,
746798 } ,
747799 { Key : 'ghr:Type' , Value : expectedValues . type } ,
748800 { Key : 'ghr:Owner' , Value : REPO_NAME } ,
0 commit comments