import test from "ava" ; import { faastGoogle } from "../index" ; import { defaultGcWorker } from "../src/google/google-faast" ; import * as functions from "./fixtures/functions" ; import { checkResourcesCleanedUp } from "./fixtures/util" ; import { getGoogleResources } from "./fixtures/util-google" ; test ( "remote google garbage collector works for functions that are called" , async ( t ) => { const mod = await faastGoogle ( functions , { mode : "queue" , gc : "off" , description : t . title } ) ; await mod . functions . hello ( "gc-test" ) ; await mod . cleanup ( { deleteResources : false } ) ; const mod2 = await faastGoogle ( functions , { gc : "force" , retentionInDays : 0 , description : t . title , _gcWorker : async ( work , services ) => { if ( work . trampoline === mod . state . resources . trampoline ) { await defaultGcWorker ( work , services ) ; } } } ) ; await mod2 . cleanup ( ) ; await checkResourcesCleanedUp ( t , await getGoogleResources ( mod ) ) ; await mod . cleanup ( ) ; } ) ; test ( "remote google garbage collector works for functions that are never called" , async ( t ) => { const mod = await faastGoogle ( functions , { mode : "queue" , gc : "off" , description : t . title } ) ; await mod . cleanup ( { deleteResources : false } ) ; const mod2 = await faastGoogle ( functions , { gc : "force" , retentionInDays : 0 , description : t . title , _gcWorker : async ( work , services ) => { if ( work . trampoline === mod . state . resources . trampoline ) { await defaultGcWorker ( work , services ) ; } } } ) ; await mod2 . cleanup ( ) ; await checkResourcesCleanedUp ( t , await getGoogleResources ( mod ) ) ; await mod . cleanup ( ) ; } ) ;