Skip to content

Commit 98af9d0

Browse files
committed
fix(vms): fix emulator tests
1 parent 5d0375d commit 98af9d0

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/actions/test/unit/ec2.test.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ describe("VMs", () => {
8282
let ec2: EC2Client
8383

8484
beforeAll(async () => {
85-
ec2 = await createEC2Client()
86-
ssmClient = await createSSMClient()
85+
if (envType === TestingEnvironment.PRODUCTION) {
86+
ec2 = await createEC2Client()
87+
ssmClient = await createSSMClient()
88+
}
8789
})
8890

8991
if (envType === TestingEnvironment.PRODUCTION) {
@@ -335,9 +337,11 @@ describe("VMs", () => {
335337

336338
// delete users and mock ceremonies
337339
await cleanUpMockUsers(adminAuth, adminFirestore, users)
338-
await cleanUpRecursively(adminFirestore, ceremonyId)
339-
await cleanUpRecursively(adminFirestore, secondCeremonyId)
340-
await cleanUpRecursively(adminFirestore, ceremonyClosed.uid)
340+
try {
341+
await cleanUpRecursively(adminFirestore, ceremonyId)
342+
await cleanUpRecursively(adminFirestore, secondCeremonyId)
343+
await cleanUpRecursively(adminFirestore, ceremonyClosed.uid)
344+
} catch (error: any) {}
341345

342346
// remove local files
343347
fs.rmdirSync(`${outputDirectory}`, { recursive: true })

packages/backend/src/functions/ceremony.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
getAWSVariables
3535
} from "../lib/utils"
3636
import { LogLevel } from "../types/enums"
37+
import { EC2Client } from "@aws-sdk/client-ec2"
3738

3839
dotenv.config()
3940

@@ -307,14 +308,17 @@ export const finalizeCeremony = functions
307308

308309
printLog(`Ceremony ${ceremonyDoc.id} correctly finalized - Coordinator ${participantDoc.id}`, LogLevel.INFO)
309310

310-
const ec2Client = await createEC2Client()
311+
// avoid creating the object if none of the circuits use a VM
312+
let ec2Client: EC2Client
311313

312314
// terminate the VMs
313315
for (const circuit of circuits) {
314316
const circuitData = circuit.data()
315317
const { verification } = circuitData
316318

317319
if (verification.cfOrVm === CircuitContributionVerificationMechanism.VM) {
320+
// avoid creating object twice if the Circuit is not using a VM
321+
ec2Client = await createEC2Client()
318322
const { vm } = verification
319323
await terminateEC2Instance(ec2Client, vm.vmInstanceId)
320324
}

0 commit comments

Comments
 (0)