Skip to content

Commit

Permalink
fix(vms): fix emulator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Jul 3, 2023
1 parent 5d0375d commit 98af9d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 9 additions & 5 deletions packages/actions/test/unit/ec2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ describe("VMs", () => {
let ec2: EC2Client

beforeAll(async () => {
ec2 = await createEC2Client()
ssmClient = await createSSMClient()
if (envType === TestingEnvironment.PRODUCTION) {
ec2 = await createEC2Client()
ssmClient = await createSSMClient()
}
})

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

// delete users and mock ceremonies
await cleanUpMockUsers(adminAuth, adminFirestore, users)
await cleanUpRecursively(adminFirestore, ceremonyId)
await cleanUpRecursively(adminFirestore, secondCeremonyId)
await cleanUpRecursively(adminFirestore, ceremonyClosed.uid)
try {
await cleanUpRecursively(adminFirestore, ceremonyId)
await cleanUpRecursively(adminFirestore, secondCeremonyId)
await cleanUpRecursively(adminFirestore, ceremonyClosed.uid)
} catch (error: any) {}

// remove local files
fs.rmdirSync(`${outputDirectory}`, { recursive: true })
Expand Down
6 changes: 5 additions & 1 deletion packages/backend/src/functions/ceremony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
getAWSVariables
} from "../lib/utils"
import { LogLevel } from "../types/enums"
import { EC2Client } from "@aws-sdk/client-ec2"

dotenv.config()

Expand Down Expand Up @@ -307,14 +308,17 @@ export const finalizeCeremony = functions

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

const ec2Client = await createEC2Client()
// avoid creating the object if none of the circuits use a VM
let ec2Client: EC2Client

// terminate the VMs
for (const circuit of circuits) {
const circuitData = circuit.data()
const { verification } = circuitData

if (verification.cfOrVm === CircuitContributionVerificationMechanism.VM) {
// avoid creating object twice if the Circuit is not using a VM
ec2Client = await createEC2Client()
const { vm } = verification
await terminateEC2Instance(ec2Client, vm.vmInstanceId)
}
Expand Down

0 comments on commit 98af9d0

Please sign in to comment.