@@ -21,6 +21,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
2121import ScaleError from './../scale-runners/ScaleError' ;
2222import { createRunner , listEC2Runners , tag , terminateRunner , untag } from './runners' ;
2323import type { RunnerInfo , RunnerInputParameters , RunnerType } from './runners.d' ;
24+ import { LambdaRunnerSource } from '../scale-runners/scale-up' ;
2425
2526process . env . AWS_REGION = 'eu-east-1' ;
2627const mockEC2Client = mockClient ( EC2Client ) ;
@@ -319,13 +320,15 @@ describe('create runner', () => {
319320 capacityType : 'spot' ,
320321 type : 'Org' ,
321322 scaleErrors : [ 'UnfulfillableCapacity' , 'MaxSpotInstanceCountExceeded' ] ,
323+ source : 'scale-up-lambda' ,
322324 } ;
323325
324326 const defaultExpectedFleetRequestValues : ExpectedFleetRequestValues = {
325327 type : 'Org' ,
326328 capacityType : 'spot' ,
327329 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
328330 totalTargetCapacity : 1 ,
331+ source : 'scale-up-lambda' ,
329332 } ;
330333
331334 beforeEach ( ( ) => {
@@ -366,6 +369,25 @@ describe('create runner', () => {
366369 } ) ;
367370 } ) ;
368371
372+ it ( 'calls create fleet of multiple instances with pool-lambda source when specified' , async ( ) => {
373+ const instances = [ { InstanceIds : [ 'i-1234' , 'i-5678' , 'i-9012' ] } ] ;
374+
375+ mockEC2Client . on ( CreateFleetCommand ) . resolves ( { Instances : instances } ) ;
376+
377+ await createRunner ( {
378+ ...createRunnerConfig ( { ...defaultRunnerConfig , source : 'pool-lambda' } ) ,
379+ numberOfRunners : 3 ,
380+ } ) ;
381+
382+ expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
383+ ...expectedCreateFleetRequest ( {
384+ ...defaultExpectedFleetRequestValues ,
385+ totalTargetCapacity : 3 ,
386+ source : 'pool-lambda' ,
387+ } ) ,
388+ } ) ;
389+ } ) ;
390+
369391 it ( 'calls create fleet of 1 instance with the on-demand capacity' , async ( ) => {
370392 await createRunner ( createRunnerConfig ( { ...defaultRunnerConfig , capacityType : 'on-demand' } ) ) ;
371393 expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
@@ -414,6 +436,7 @@ describe('create runner', () => {
414436 Name : 'my-ami-id-param' ,
415437 } ) ;
416438 } ) ;
439+
417440 it ( 'calls create fleet of 1 instance with runner tracing enabled' , async ( ) => {
418441 tracer . getRootXrayTraceId = vi . fn ( ) . mockReturnValue ( '123' ) ;
419442
@@ -427,6 +450,28 @@ describe('create runner', () => {
427450 } ) ;
428451 } ) ;
429452
453+ it ( 'calls create fleet with source set to scale-up-lambda when source is specified' , async ( ) => {
454+ await createRunner ( createRunnerConfig ( { ...defaultRunnerConfig , source : 'scale-up-lambda' } ) ) ;
455+
456+ expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
457+ ...expectedCreateFleetRequest ( {
458+ ...defaultExpectedFleetRequestValues ,
459+ source : 'scale-up-lambda' ,
460+ } ) ,
461+ } ) ;
462+ } ) ;
463+
464+ it ( 'calls create fleet with source set to pool-lambda when source is specified' , async ( ) => {
465+ await createRunner ( createRunnerConfig ( { ...defaultRunnerConfig , source : 'pool-lambda' } ) ) ;
466+
467+ expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
468+ ...expectedCreateFleetRequest ( {
469+ ...defaultExpectedFleetRequestValues ,
470+ source : 'pool-lambda' ,
471+ } ) ,
472+ } ) ;
473+ } ) ;
474+
430475 it ( 'overrides SubnetId when specified in ec2OverrideConfig' , async ( ) => {
431476 await createRunner ( {
432477 ...createRunnerConfig ( defaultRunnerConfig ) ,
@@ -643,12 +688,14 @@ describe('create runner with errors', () => {
643688 capacityType : 'spot' ,
644689 type : 'Repo' ,
645690 scaleErrors : [ 'UnfulfillableCapacity' , 'MaxSpotInstanceCountExceeded' ] ,
691+ source : 'scale-up-lambda' ,
646692 } ;
647693 const defaultExpectedFleetRequestValues : ExpectedFleetRequestValues = {
648694 type : 'Repo' ,
649695 capacityType : 'spot' ,
650696 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
651697 totalTargetCapacity : 1 ,
698+ source : 'scale-up-lambda' ,
652699 } ;
653700 beforeEach ( ( ) => {
654701 vi . clearAllMocks ( ) ;
@@ -757,12 +804,14 @@ describe('create runner with errors fail over to OnDemand', () => {
757804 type : 'Repo' ,
758805 onDemandFailoverOnError : [ 'InsufficientInstanceCapacity' ] ,
759806 scaleErrors : [ 'UnfulfillableCapacity' , 'MaxSpotInstanceCountExceeded' ] ,
807+ source : 'scale-up-lambda' ,
760808 } ;
761809 const defaultExpectedFleetRequestValues : ExpectedFleetRequestValues = {
762810 type : 'Repo' ,
763811 capacityType : 'spot' ,
764812 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
765813 totalTargetCapacity : 1 ,
814+ source : 'scale-up-lambda' ,
766815 } ;
767816 beforeEach ( ( ) => {
768817 vi . clearAllMocks ( ) ;
@@ -915,6 +964,7 @@ interface RunnerConfig {
915964 tracingEnabled ?: boolean ;
916965 onDemandFailoverOnError ?: string [ ] ;
917966 scaleErrors : string [ ] ;
967+ source : LambdaRunnerSource ;
918968}
919969
920970function createRunnerConfig ( runnerConfig : RunnerConfig ) : RunnerInputParameters {
@@ -935,6 +985,7 @@ function createRunnerConfig(runnerConfig: RunnerConfig): RunnerInputParameters {
935985 tracingEnabled : runnerConfig . tracingEnabled ,
936986 onDemandFailoverOnError : runnerConfig . onDemandFailoverOnError ,
937987 scaleErrors : runnerConfig . scaleErrors ,
988+ source : runnerConfig . source ,
938989 } ;
939990}
940991
@@ -946,14 +997,15 @@ interface ExpectedFleetRequestValues {
946997 totalTargetCapacity : number ;
947998 imageId ?: string ;
948999 tracingEnabled ?: boolean ;
1000+ source : LambdaRunnerSource ;
9491001}
9501002
9511003function expectedCreateFleetRequest ( expectedValues : ExpectedFleetRequestValues ) : CreateFleetCommandInput {
9521004 const tags = [
9531005 { Key : 'ghr:Application' , Value : 'github-action-runner' } ,
9541006 {
9551007 Key : 'ghr:created_by' ,
956- Value : expectedValues . totalTargetCapacity > 1 ? 'pool-lambda' : 'scale-up-lambda' ,
1008+ Value : expectedValues . source ,
9571009 } ,
9581010 { Key : 'ghr:Type' , Value : expectedValues . type } ,
9591011 { Key : 'ghr:Owner' , Value : REPO_NAME } ,
0 commit comments