Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blocking functions in the emulator when using multiple codebases #6504

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix blocking functions in the emulator when using multiple codebases (#6504).
4 changes: 2 additions & 2 deletions src/emulator/functionsEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
createHubServer(): express.Application {
// TODO(samstern): Should not need this here but some tests are directly calling this method
// because FunctionsEmulator.start() used to not be test safe.
this.workQueue.start();

Check warning on line 269 in src/emulator/functionsEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

const hub = express();

Expand Down Expand Up @@ -308,15 +308,15 @@
const multicastHandler: express.RequestHandler = (req: express.Request, res) => {
const projectId = req.params.project_id;
const rawBody = (req as RequestWithRawBody).rawBody;
const event = JSON.parse(rawBody.toString());

Check warning on line 311 in src/emulator/functionsEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value
let triggerKey: string;
if (req.headers["content-type"]?.includes("cloudevent")) {
triggerKey = `${this.args.projectId}:${event.type}`;

Check warning on line 314 in src/emulator/functionsEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Invalid type "any" of template literal expression

Check warning on line 314 in src/emulator/functionsEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .type on an `any` value
} else {
triggerKey = `${this.args.projectId}:${event.eventType}`;

Check warning on line 316 in src/emulator/functionsEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Invalid type "any" of template literal expression

Check warning on line 316 in src/emulator/functionsEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .eventType on an `any` value
}
if (event.data.bucket) {

Check warning on line 318 in src/emulator/functionsEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .data on an `any` value
triggerKey += `:${event.data.bucket}`;

Check warning on line 319 in src/emulator/functionsEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Invalid type "any" of template literal expression

Check warning on line 319 in src/emulator/functionsEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .data on an `any` value
}
const triggers = this.multicastTriggers[triggerKey] || [];

Expand Down Expand Up @@ -361,7 +361,7 @@
return hub;
}

async sendRequest(trigger: EmulatedTriggerDefinition, body?: any) {

Check warning on line 364 in src/emulator/functionsEmulator.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Missing return type on function
const record = this.getTriggerRecordByKey(this.getTriggerKey(trigger));
const pool = this.workerPools[record.backend.codebase];
if (!pool.readyForWork(trigger.id)) {
Expand Down Expand Up @@ -566,8 +566,6 @@
} else {
this.workerPools[emulatableBackend.codebase].refresh();
}
// reset blocking functions config for reloads
this.blockingFunctionsConfig = {};

// When force is true we set up all triggers, otherwise we only set up
// triggers which have a unique function name
Expand Down Expand Up @@ -1436,6 +1434,8 @@

async reloadTriggers() {
this.triggerGeneration++;
// reset blocking functions config for reloads
this.blockingFunctionsConfig = {};
for (const backend of this.args.emulatableBackends) {
await this.loadTriggers(backend);
}
Expand Down