@@ -22,6 +22,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
2222import ScaleError from './../scale-runners/ScaleError' ;
2323import { createRunner , listEC2Runners , tag , terminateRunner , untag } from './runners' ;
2424import type { RunnerInfo , RunnerInputParameters , RunnerType } from './runners.d' ;
25+ import { LambdaRunnerSource } from '../scale-runners/scale-up' ;
2526
2627process . env . AWS_REGION = 'eu-east-1' ;
2728const mockEC2Client = mockClient ( EC2Client ) ;
@@ -319,13 +320,16 @@ describe('create runner', () => {
319320 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
320321 capacityType : 'spot' ,
321322 type : 'Org' ,
323+ scaleErrors : [ ] ,
324+ source : 'scale-up-lambda' ,
322325 } ;
323326
324327 const defaultExpectedFleetRequestValues : ExpectedFleetRequestValues = {
325328 type : 'Org' ,
326329 capacityType : 'spot' ,
327330 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
328331 totalTargetCapacity : 1 ,
332+ source : 'scale-up-lambda' ,
329333 } ;
330334
331335 beforeEach ( ( ) => {
@@ -366,6 +370,25 @@ describe('create runner', () => {
366370 } ) ;
367371 } ) ;
368372
373+ it ( 'calls create fleet of multiple instances with pool-lambda source when specified' , async ( ) => {
374+ const instances = [ { InstanceIds : [ 'i-1234' , 'i-5678' , 'i-9012' ] } ] ;
375+
376+ mockEC2Client . on ( CreateFleetCommand ) . resolves ( { Instances : instances } ) ;
377+
378+ await createRunner ( {
379+ ...createRunnerConfig ( { ...defaultRunnerConfig , source : 'pool-lambda' } ) ,
380+ numberOfRunners : 3 ,
381+ } ) ;
382+
383+ expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
384+ ...expectedCreateFleetRequest ( {
385+ ...defaultExpectedFleetRequestValues ,
386+ totalTargetCapacity : 3 ,
387+ source : 'pool-lambda' ,
388+ } ) ,
389+ } ) ;
390+ } ) ;
391+
369392 it ( 'calls create fleet of 1 instance with the on-demand capacity' , async ( ) => {
370393 await createRunner ( createRunnerConfig ( { ...defaultRunnerConfig , capacityType : 'on-demand' } ) ) ;
371394 expect ( mockEC2Client ) . toHaveReceivedCommandWith ( CreateFleetCommand , {
@@ -426,6 +449,28 @@ describe('create runner', () => {
426449 } ) ,
427450 } ) ;
428451 } ) ;
452+
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+ } ) ;
429474} ) ;
430475
431476describe ( 'create runner with errors' , ( ) => {
@@ -434,12 +479,14 @@ describe('create runner with errors', () => {
434479 capacityType : 'spot' ,
435480 type : 'Repo' ,
436481 scaleErrors : [ 'UnfulfillableCapacity' , 'MaxSpotInstanceCountExceeded' ] ,
482+ source : 'scale-up-lambda' ,
437483 } ;
438484 const defaultExpectedFleetRequestValues : ExpectedFleetRequestValues = {
439485 type : 'Repo' ,
440486 capacityType : 'spot' ,
441487 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
442488 totalTargetCapacity : 1 ,
489+ source : 'scale-up-lambda' ,
443490 } ;
444491 beforeEach ( ( ) => {
445492 vi . clearAllMocks ( ) ;
@@ -547,12 +594,15 @@ describe('create runner with errors fail over to OnDemand', () => {
547594 capacityType : 'spot' ,
548595 type : 'Repo' ,
549596 onDemandFailoverOnError : [ 'InsufficientInstanceCapacity' ] ,
597+ scaleErrors : [ ] ,
598+ source : 'scale-up-lambda' ,
550599 } ;
551600 const defaultExpectedFleetRequestValues : ExpectedFleetRequestValues = {
552601 type : 'Repo' ,
553602 capacityType : 'spot' ,
554603 allocationStrategy : SpotAllocationStrategy . CAPACITY_OPTIMIZED ,
555604 totalTargetCapacity : 1 ,
605+ source : 'scale-up-lambda' ,
556606 } ;
557607 beforeEach ( ( ) => {
558608 vi . clearAllMocks ( ) ;
@@ -706,6 +756,7 @@ interface RunnerConfig {
706756 onDemandFailoverOnError ?: string [ ] ;
707757 scaleErrors : string [ ] ;
708758 useDedicatedHost ?: boolean ;
759+ source : LambdaRunnerSource ;
709760}
710761
711762function createRunnerConfig ( runnerConfig : RunnerConfig ) : RunnerInputParameters {
@@ -727,6 +778,7 @@ function createRunnerConfig(runnerConfig: RunnerConfig): RunnerInputParameters {
727778 onDemandFailoverOnError : runnerConfig . onDemandFailoverOnError ,
728779 scaleErrors : runnerConfig . scaleErrors ,
729780 useDedicatedHost : runnerConfig . useDedicatedHost ,
781+ source : runnerConfig . source ,
730782 } ;
731783}
732784
@@ -738,14 +790,15 @@ interface ExpectedFleetRequestValues {
738790 totalTargetCapacity : number ;
739791 imageId ?: string ;
740792 tracingEnabled ?: boolean ;
793+ source : LambdaRunnerSource ;
741794}
742795
743796function expectedCreateFleetRequest ( expectedValues : ExpectedFleetRequestValues ) : CreateFleetCommandInput {
744797 const tags = [
745798 { Key : 'ghr:Application' , Value : 'github-action-runner' } ,
746799 {
747800 Key : 'ghr:created_by' ,
748- Value : expectedValues . totalTargetCapacity > 1 ? 'pool-lambda' : 'scale-up-lambda' ,
801+ Value : expectedValues . source ,
749802 } ,
750803 { Key : 'ghr:Type' , Value : expectedValues . type } ,
751804 { Key : 'ghr:Owner' , Value : REPO_NAME } ,
0 commit comments