@@ -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 ) ;
@@ -318,13 +319,16 @@ describe('create runner', () => {
318319 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
319320 capacityType : 'spot' ,
320321 type : 'Org' ,
322+ scaleErrors : [ ] ,
323+ source : 'scale-up-lambda' ,
321324 } ;
322325
323326 const defaultExpectedFleetRequestValues : ExpectedFleetRequestValues = {
324327 type : 'Org' ,
325328 capacityType : 'spot' ,
326329 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
327330 totalTargetCapacity : 1 ,
331+ source : 'scale-up-lambda' ,
328332 } ;
329333
330334 beforeEach ( ( ) => {
@@ -365,6 +369,25 @@ describe('create runner', () => {
365369 } ) ;
366370 } ) ;
367371
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+
368391 it ( 'calls create fleet of 1 instance with the on-demand capacity' , async ( ) => {
369392 await createRunner ( createRunnerConfig ( { ...defaultRunnerConfig , capacityType : 'on-demand' } ) ) ;
370393 expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
@@ -425,6 +448,28 @@ describe('create runner', () => {
425448 } ) ,
426449 } ) ;
427450 } ) ;
451+
452+ it ( 'calls create fleet with source set to scale-up-lambda when source is specified' , async ( ) => {
453+ await createRunner ( createRunnerConfig ( { ...defaultRunnerConfig , source : 'scale-up-lambda' } ) ) ;
454+
455+ expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
456+ ...expectedCreateFleetRequest ( {
457+ ...defaultExpectedFleetRequestValues ,
458+ source : 'scale-up-lambda' ,
459+ } ) ,
460+ } ) ;
461+ } ) ;
462+
463+ it ( 'calls create fleet with source set to pool-lambda when source is specified' , async ( ) => {
464+ await createRunner ( createRunnerConfig ( { ...defaultRunnerConfig , source : 'pool-lambda' } ) ) ;
465+
466+ expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
467+ ...expectedCreateFleetRequest ( {
468+ ...defaultExpectedFleetRequestValues ,
469+ source : 'pool-lambda' ,
470+ } ) ,
471+ } ) ;
472+ } ) ;
428473} ) ;
429474
430475describe ( 'create runner with errors' , ( ) => {
@@ -433,12 +478,14 @@ describe('create runner with errors', () => {
433478 capacityType : 'spot' ,
434479 type : 'Repo' ,
435480 scaleErrors : [ 'UnfulfillableCapacity' , 'MaxSpotInstanceCountExceeded' ] ,
481+ source : 'scale-up-lambda' ,
436482 } ;
437483 const defaultExpectedFleetRequestValues : ExpectedFleetRequestValues = {
438484 type : 'Repo' ,
439485 capacityType : 'spot' ,
440486 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
441487 totalTargetCapacity : 1 ,
488+ source : 'scale-up-lambda' ,
442489 } ;
443490 beforeEach ( ( ) => {
444491 vi . clearAllMocks ( ) ;
@@ -546,12 +593,15 @@ describe('create runner with errors fail over to OnDemand', () => {
546593 capacityType : 'spot' ,
547594 type : 'Repo' ,
548595 onDemandFailoverOnError : [ 'InsufficientInstanceCapacity' ] ,
596+ scaleErrors : [ ] ,
597+ source : 'scale-up-lambda' ,
549598 } ;
550599 const defaultExpectedFleetRequestValues : ExpectedFleetRequestValues = {
551600 type : 'Repo' ,
552601 capacityType : 'spot' ,
553602 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
554603 totalTargetCapacity : 1 ,
604+ source : 'scale-up-lambda' ,
555605 } ;
556606 beforeEach ( ( ) => {
557607 vi . clearAllMocks ( ) ;
@@ -704,6 +754,7 @@ interface RunnerConfig {
704754 tracingEnabled ?: boolean ;
705755 onDemandFailoverOnError ?: string [ ] ;
706756 scaleErrors : string [ ] ;
757+ source : LambdaRunnerSource ;
707758}
708759
709760function createRunnerConfig ( runnerConfig : RunnerConfig ) : RunnerInputParameters {
@@ -724,6 +775,7 @@ function createRunnerConfig(runnerConfig: RunnerConfig): RunnerInputParameters {
724775 tracingEnabled : runnerConfig . tracingEnabled ,
725776 onDemandFailoverOnError : runnerConfig . onDemandFailoverOnError ,
726777 scaleErrors : runnerConfig . scaleErrors ,
778+ source : runnerConfig . source ,
727779 } ;
728780}
729781
@@ -735,14 +787,15 @@ interface ExpectedFleetRequestValues {
735787 totalTargetCapacity : number ;
736788 imageId ?: string ;
737789 tracingEnabled ?: boolean ;
790+ source : LambdaRunnerSource ;
738791}
739792
740793function expectedCreateFleetRequest ( expectedValues : ExpectedFleetRequestValues ) : CreateFleetCommandInput {
741794 const tags = [
742795 { Key : 'ghr:Application' , Value : 'github-action-runner' } ,
743796 {
744797 Key : 'ghr:created_by' ,
745- Value : expectedValues . totalTargetCapacity > 1 ? 'pool-lambda' : 'scale-up-lambda' ,
798+ Value : expectedValues . source ,
746799 } ,
747800 { Key : 'ghr:Type' , Value : expectedValues . type } ,
748801 { Key : 'ghr:Owner' , Value : REPO_NAME } ,
0 commit comments