Skip to content

Commit 036444d

Browse files
committed
fix(integration_test): verify that services are properly torn down
1 parent 67a4088 commit 036444d

File tree

2 files changed

+73
-12
lines changed

2 files changed

+73
-12
lines changed

integration_test/cloudbuild-v2.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,22 @@ timeout: "3600s"
99

1010
steps:
1111
# Build SDK and run all V2 test suites sequentially
12-
- name: "node:20"
12+
# Using the official Google Cloud SDK image which includes gcloud pre-installed
13+
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk:stable"
1314
id: "build-sdk-and-test-v2"
1415
entrypoint: "bash"
1516
args:
1617
- "-c"
1718
- |
19+
# Install Node.js 20.x
20+
echo "Installing Node.js 20..."
21+
apt-get update -qq
22+
apt-get install -y -qq curl
23+
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
24+
apt-get install -y -qq nodejs
25+
node --version
26+
npm --version
27+
1828
# Step 1: Build and pack the firebase-functions SDK from source
1929
echo "Building firebase-functions SDK from source..."
2030
pwd
@@ -32,7 +42,7 @@ steps:
3242
npm ci
3343
# Install firebase-tools globally
3444
npm install -g firebase-tools
35-
# gcloud is pre-installed in Cloud Build, just set the project
45+
# gcloud is already available in this image
3646
gcloud config set project functions-integration-tests-v2
3747
# Verify tools are installed
3848
firebase --version

integration_test/scripts/run-tests.js

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -560,16 +560,38 @@ class TestRunner {
560560
await this.exec(
561561
`firebase functions:delete ${functionName} --project ${metadata.projectId} --region ${
562562
metadata.region || DEFAULT_REGION
563-
} --force`,
564-
{ silent: true }
563+
} --force`
565564
);
566-
this.log(` ✅ Deleted function via Firebase CLI: ${functionName}`, "success");
567-
deleted = true;
565+
566+
// Verify the function was actually deleted
567+
this.log(` Verifying deletion of ${functionName}...`, "info");
568+
try {
569+
const listResult = await this.exec(
570+
`firebase functions:list --project ${metadata.projectId}`,
571+
{ silent: true }
572+
);
573+
574+
// Check if function still exists in the list
575+
const functionStillExists = listResult.stdout.includes(functionName);
576+
577+
if (!functionStillExists) {
578+
this.log(` ✅ Verified: Function deleted via Firebase CLI: ${functionName}`, "success");
579+
deleted = true;
580+
} else {
581+
this.log(` ⚠️ Function still exists after Firebase CLI delete: ${functionName}`, "warn");
582+
}
583+
} catch (listError) {
584+
// If we can't list functions, assume deletion worked
585+
this.log(` ✅ Deleted function via Firebase CLI (unverified): ${functionName}`, "success");
586+
deleted = true;
587+
}
568588
} catch (error) {
569589
this.log(` ⚠️ Firebase CLI delete failed for ${functionName}: ${error.message}`, "warn");
590+
}
570591

571-
// For v2 functions, if Firebase fails (likely due to missing scheduler job),
572-
// try to delete the Cloud Run service directly
592+
// If not deleted yet, try alternative methods
593+
if (!deleted) {
594+
// For v2 functions, try to delete the Cloud Run service directly
573595
if (metadata.projectId === "functions-integration-tests-v2") {
574596
this.log(` Attempting Cloud Run service deletion for v2 function...`, "warn");
575597
try {
@@ -579,8 +601,22 @@ class TestRunner {
579601
} --project=${metadata.projectId} --quiet`,
580602
{ silent: true }
581603
);
582-
this.log(` ✅ Deleted function as Cloud Run service: ${functionName}`, "success");
583-
deleted = true;
604+
605+
// Verify deletion
606+
try {
607+
await this.exec(
608+
`gcloud run services describe ${functionName} --region=${
609+
metadata.region || DEFAULT_REGION
610+
} --project=${metadata.projectId}`,
611+
{ silent: true }
612+
);
613+
// If describe succeeds, function still exists
614+
this.log(` ⚠️ Cloud Run service still exists after deletion: ${functionName}`, "warn");
615+
} catch {
616+
// If describe fails, function was deleted
617+
this.log(` ✅ Deleted function as Cloud Run service: ${functionName}`, "success");
618+
deleted = true;
619+
}
584620
} catch (runError) {
585621
this.log(` ⚠️ Cloud Run delete failed: ${runError.message}`, "warn");
586622
}
@@ -595,8 +631,23 @@ class TestRunner {
595631
} --project=${metadata.projectId} --quiet`,
596632
{ silent: true }
597633
);
598-
this.log(` ✅ Deleted function via gcloud: ${functionName}`, "success");
599-
deleted = true;
634+
635+
// Verify deletion
636+
try {
637+
await this.exec(
638+
`gcloud functions describe ${functionName} --region=${
639+
metadata.region || DEFAULT_REGION
640+
} --project=${metadata.projectId}`,
641+
{ silent: true }
642+
);
643+
// If describe succeeds, function still exists
644+
this.log(` ⚠️ Function still exists after gcloud delete: ${functionName}`, "warn");
645+
deleted = false;
646+
} catch {
647+
// If describe fails, function was deleted
648+
this.log(` ✅ Deleted function via gcloud: ${functionName}`, "success");
649+
deleted = true;
650+
}
600651
} catch (e) {
601652
this.log(` ❌ Failed to delete function ${functionName} via any method`, "error");
602653
this.log(` Last error: ${e.message}`, "error");

0 commit comments

Comments
 (0)