Skip to content

Commit f96ba43

Browse files
committed
fix(integration_tests): scope cleanup to declared project
1 parent 1af4029 commit f96ba43

File tree

5 files changed

+105
-110
lines changed

5 files changed

+105
-110
lines changed

integration_test/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,20 +413,20 @@ The integration tests use **separate Cloud Build configurations** for V1 and V2
413413
**V1 Tests:**
414414
```bash
415415
# Run V1 tests on functions-integration-tests project
416-
gcloud builds submit --config=integration_test/cloudbuild-v1.yaml
416+
gcloud builds submit --config=integration_test/cloudbuild-v1.yaml --project=functions-integration-tests
417417
```
418418

419419
**V2 Tests:**
420420
```bash
421421
# Run V2 tests on functions-integration-tests-v2 project
422-
gcloud builds submit --config=integration_test/cloudbuild-v2.yaml
422+
gcloud builds submit --config=integration_test/cloudbuild-v2.yaml --project=functions-integration-tests-v2
423423
```
424424

425425
**Both Tests (Parallel):**
426426
```bash
427427
# Run both V1 and V2 tests simultaneously
428-
gcloud builds submit --config=integration_test/cloudbuild-v1.yaml &
429-
gcloud builds submit --config=integration_test/cloudbuild-v2.yaml &
428+
gcloud builds submit --config=integration_test/cloudbuild-v1.yaml --project=functions-integration-tests &
429+
gcloud builds submit --config=integration_test/cloudbuild-v2.yaml --project=functions-integration-tests-v2 &
430430
wait
431431
```
432432

integration_test/cloudbuild-v1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ steps:
3232
npm install -g firebase-tools
3333
# Install gcloud CLI for Cloud Tasks cleanup
3434
curl https://sdk.cloud.google.com | bash
35-
export PATH="$PATH:/root/google-cloud-sdk/bin"
35+
export PATH="$$PATH:/root/google-cloud-sdk/bin"
3636
# Verify tools are installed
3737
firebase --version
3838
gcloud --version

integration_test/cloudbuild-v2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ steps:
3232
npm install -g firebase-tools
3333
# Install gcloud CLI for Cloud Tasks cleanup
3434
curl https://sdk.cloud.google.com | bash
35-
export PATH="$PATH:/root/google-cloud-sdk/bin"
35+
export PATH="$$PATH:/root/google-cloud-sdk/bin"
3636
# Verify tools are installed
3737
firebase --version
3838
gcloud --version

integration_test/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"test:all:sequential": "node scripts/run-tests.js --sequential",
1818
"test:v1:auth-before-create": "node scripts/run-tests.js v1_auth_before_create",
1919
"test:v1:auth-before-signin": "node scripts/run-tests.js v1_auth_before_signin",
20-
"cloudbuild:v1": "gcloud builds submit --config=cloudbuild-v1.yaml",
21-
"cloudbuild:v2": "gcloud builds submit --config=cloudbuild-v2.yaml",
22-
"cloudbuild:both": "gcloud builds submit --config=cloudbuild-v1.yaml & gcloud builds submit --config=cloudbuild-v2.yaml & wait",
20+
"cloudbuild:v1": "gcloud builds submit --config=cloudbuild-v1.yaml --project=functions-integration-tests",
21+
"cloudbuild:v2": "gcloud builds submit --config=cloudbuild-v2.yaml --project=functions-integration-tests-v2",
22+
"cloudbuild:both": "gcloud builds submit --config=cloudbuild-v1.yaml --project=functions-integration-tests & gcloud builds submit --config=cloudbuild-v2.yaml --project=functions-integration-tests-v2 & wait",
2323
"cloudbuild:all": "npm run cloudbuild:both",
2424
"cleanup": "./scripts/cleanup-suite.sh",
2525
"cleanup:list": "./scripts/cleanup-suite.sh --list-artifacts",

integration_test/scripts/run-tests.js

Lines changed: 96 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -703,82 +703,80 @@ class TestRunner {
703703
async cleanupExistingResources() {
704704
this.log("🧹 Checking for existing test functions...", "warn");
705705

706-
const { v1ProjectId, v2ProjectId } = this.getProjectIds();
707-
const projects = [v1ProjectId, v2ProjectId];
706+
// Only clean up the project that's being used for this test run
707+
const projectId = this.projectId;
708+
this.log(` Checking project: ${projectId}`, "warn");
708709

709-
for (const projectId of projects) {
710-
this.log(` Checking project: ${projectId}`, "warn");
711-
712-
try {
713-
// List functions and find test functions
714-
const result = await this.exec(`firebase functions:list --project ${projectId}`, {
715-
silent: true,
716-
});
710+
try {
711+
// List functions and find test functions
712+
const result = await this.exec(`firebase functions:list --project ${projectId}`, {
713+
silent: true,
714+
});
717715

718-
// Parse the table output from firebase functions:list
719-
const lines = result.stdout.split("\n");
720-
const testFunctions = [];
721-
722-
for (const line of lines) {
723-
// Look for table rows with function names (containing │)
724-
if (line.includes("│") && line.includes("Test")) {
725-
const parts = line.split("│");
726-
if (parts.length >= 2) {
727-
const functionName = parts[1].trim();
728-
// Check if it's a test function (contains Test + test run ID pattern)
729-
if (functionName.match(/Test.*t[a-z0-9]{7,10}/)) {
730-
testFunctions.push(functionName);
731-
}
716+
// Parse the table output from firebase functions:list
717+
const lines = result.stdout.split("\n");
718+
const testFunctions = [];
719+
720+
for (const line of lines) {
721+
// Look for table rows with function names (containing │)
722+
if (line.includes("│") && line.includes("Test")) {
723+
const parts = line.split("│");
724+
if (parts.length >= 2) {
725+
const functionName = parts[1].trim();
726+
// Check if it's a test function (contains Test + test run ID pattern)
727+
if (functionName.match(/Test.*t[a-z0-9]{7,10}/)) {
728+
testFunctions.push(functionName);
732729
}
733730
}
734731
}
732+
}
735733

736-
if (testFunctions.length > 0) {
737-
this.log(
738-
` Found ${testFunctions.length} test function(s) in ${projectId}. Cleaning up...`,
739-
"warn"
740-
);
734+
if (testFunctions.length > 0) {
735+
this.log(
736+
` Found ${testFunctions.length} test function(s) in ${projectId}. Cleaning up...`,
737+
"warn"
738+
);
741739

742-
for (const func of testFunctions) {
743-
try {
744-
// Function names from firebase functions:list are just the name, no region suffix
745-
const functionName = func.trim();
746-
const region = DEFAULT_REGION;
740+
for (const func of testFunctions) {
741+
try {
742+
// Function names from firebase functions:list are just the name, no region suffix
743+
const functionName = func.trim();
744+
const region = DEFAULT_REGION;
747745

748-
this.log(` Deleting function: ${functionName} in region: ${region}`, "warn");
746+
this.log(` Deleting function: ${functionName} in region: ${region}`, "warn");
749747

750-
// Try Firebase CLI first
748+
// Try Firebase CLI first
749+
try {
750+
await this.exec(
751+
`firebase functions:delete ${functionName} --project ${projectId} --region ${region} --force`,
752+
{ silent: true }
753+
);
754+
this.log(` ✅ Deleted via Firebase CLI: ${functionName}`);
755+
} catch (firebaseError) {
756+
// If Firebase CLI fails, try gcloud as fallback
757+
this.log(` Firebase CLI failed, trying gcloud for: ${functionName}`, "warn");
751758
try {
752759
await this.exec(
753-
`firebase functions:delete ${functionName} --project ${projectId} --region ${region} --force`,
760+
`gcloud functions delete ${functionName} --region=${region} --project=${projectId} --quiet`,
754761
{ silent: true }
755762
);
756-
this.log(` ✅ Deleted via Firebase CLI: ${functionName}`);
757-
} catch (firebaseError) {
758-
// If Firebase CLI fails, try gcloud as fallback
759-
this.log(` Firebase CLI failed, trying gcloud for: ${functionName}`, "warn");
760-
try {
761-
await this.exec(
762-
`gcloud functions delete ${functionName} --region=${region} --project=${projectId} --quiet`,
763-
{ silent: true }
764-
);
765-
this.log(` ✅ Deleted via gcloud: ${functionName}`);
766-
} catch (gcloudError) {
767-
this.log(` ❌ Failed to delete: ${functionName}`, "error");
768-
this.log(` Firebase error: ${firebaseError.message}`, "error");
769-
this.log(` Gcloud error: ${gcloudError.message}`, "error");
770-
}
763+
this.log(` ✅ Deleted via gcloud: ${functionName}`);
764+
} catch (gcloudError) {
765+
this.log(` ❌ Failed to delete: ${functionName}`, "error");
766+
this.log(` Firebase error: ${firebaseError.message}`, "error");
767+
this.log(` Gcloud error: ${gcloudError.message}`, "error");
771768
}
772-
} catch (e) {
773-
this.log(` ❌ Unexpected error deleting ${func}: ${e.message}`, "error");
774769
}
770+
} catch (e) {
771+
this.log(` ❌ Unexpected error deleting ${func}: ${e.message}`, "error");
775772
}
776-
} else {
777-
this.log(` ✅ No test functions found in ${projectId}`, "success");
778773
}
779-
} catch (e) {
780-
// Project might not be accessible
774+
} else {
775+
this.log(` ✅ No test functions found in ${projectId}`, "success");
781776
}
777+
} catch (e) {
778+
this.log(` ⚠️ Could not check functions in ${projectId}: ${e.message}`, "warn");
779+
// Project might not be accessible
782780
}
783781

784782
// Clean up orphaned Cloud Tasks queues
@@ -797,58 +795,55 @@ class TestRunner {
797795
async cleanupOrphanedCloudTasksQueues() {
798796
this.log(" Checking for orphaned Cloud Tasks queues...", "warn");
799797

800-
const { v1ProjectId, v2ProjectId } = this.getProjectIds();
801-
const projects = [v1ProjectId, v2ProjectId];
798+
// Only clean up the project that's being used for this test run
799+
const projectId = this.projectId;
802800
const region = DEFAULT_REGION;
801+
this.log(` Checking Cloud Tasks queues in project: ${projectId}`, "warn");
803802

804-
for (const projectId of projects) {
805-
this.log(` Checking Cloud Tasks queues in project: ${projectId}`, "warn");
806-
807-
try {
808-
// List all queues in the project
809-
const result = await this.exec(
810-
`gcloud tasks queues list --location=${region} --project=${projectId} --format="value(name)"`,
811-
{ silent: true }
812-
);
813-
814-
const queueNames = result.stdout
815-
.split("\n")
816-
.map((line) => line.trim())
817-
.filter((line) => line.length > 0);
803+
try {
804+
// List all queues in the project
805+
const result = await this.exec(
806+
`gcloud tasks queues list --location=${region} --project=${projectId} --format="value(name)"`,
807+
{ silent: true }
808+
);
818809

819-
// Find test queues (containing "Tests" and test run ID pattern)
820-
const testQueues = queueNames.filter((queueName) => {
821-
const queueId = queueName.split("/").pop(); // Extract queue ID from full path
822-
return queueId && queueId.match(/Tests.*t[a-z0-9]{7,10}/);
823-
});
810+
const queueNames = result.stdout
811+
.split("\n")
812+
.map((line) => line.trim())
813+
.filter((line) => line.length > 0);
824814

825-
if (testQueues.length > 0) {
826-
this.log(
827-
` Found ${testQueues.length} orphaned test queue(s) in ${projectId}. Cleaning up...`,
828-
"warn"
829-
);
815+
// Find test queues (containing "Tests" and test run ID pattern)
816+
const testQueues = queueNames.filter((queueName) => {
817+
const queueId = queueName.split("/").pop(); // Extract queue ID from full path
818+
return queueId && queueId.match(/Tests.*t[a-z0-9]{7,10}/);
819+
});
830820

831-
for (const queuePath of testQueues) {
832-
try {
833-
const queueId = queuePath.split("/").pop();
834-
this.log(` Deleting orphaned queue: ${queueId}`, "warn");
821+
if (testQueues.length > 0) {
822+
this.log(
823+
` Found ${testQueues.length} orphaned test queue(s) in ${projectId}. Cleaning up...`,
824+
"warn"
825+
);
835826

836-
await this.exec(
837-
`gcloud tasks queues delete ${queueId} --location=${region} --project=${projectId} --quiet`,
838-
{ silent: true }
839-
);
840-
this.log(` ✅ Deleted orphaned queue: ${queueId}`);
841-
} catch (error) {
842-
this.log(` ⚠️ Could not delete queue ${queuePath}: ${error.message}`, "warn");
843-
}
827+
for (const queuePath of testQueues) {
828+
try {
829+
const queueId = queuePath.split("/").pop();
830+
this.log(` Deleting orphaned queue: ${queueId}`, "warn");
831+
832+
await this.exec(
833+
`gcloud tasks queues delete ${queueId} --location=${region} --project=${projectId} --quiet`,
834+
{ silent: true }
835+
);
836+
this.log(` ✅ Deleted orphaned queue: ${queueId}`);
837+
} catch (error) {
838+
this.log(` ⚠️ Could not delete queue ${queuePath}: ${error.message}`, "warn");
844839
}
845-
} else {
846-
this.log(` ✅ No orphaned test queues found in ${projectId}`, "success");
847840
}
848-
} catch (e) {
849-
// Project might not be accessible or Cloud Tasks API not enabled
850-
this.log(` ⚠️ Could not check queues in ${projectId}: ${e.message}`, "warn");
841+
} else {
842+
this.log(` ✅ No orphaned test queues found in ${projectId}`, "success");
851843
}
844+
} catch (e) {
845+
// Project might not be accessible or Cloud Tasks API not enabled
846+
this.log(` ⚠️ Could not check queues in ${projectId}: ${e.message}`, "warn");
852847
}
853848
}
854849

0 commit comments

Comments
 (0)