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

Functions breakpoint debugging #1798

Merged
merged 21 commits into from Dec 12, 2019
Merged

Functions breakpoint debugging #1798

merged 21 commits into from Dec 12, 2019

Conversation

samtstern
Copy link
Contributor

@samtstern samtstern commented Nov 14, 2019

Description

Fixes #1360

This PR enables multi-function breakpoint debugging sessions. The compromise is that when you want to enable this you have to move to a model where all executions share a single RuntimeWorker and requests are handled sequentially.

TODO:

  • API review for enabling this
  • Change API to match API review requests
  • Decide on exception handling behavior
  • Decide on code reloading behavior
  • Unit testing for workqueue

Scenarios Tested

Functions

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.helloWorld = functions.https.onRequest(async (request, response) => {
  admin.firestore().doc('/foo/bar').set({
    date: new Date()
  });
  response.send("Hello from Firebase!");
});

exports.firestoreTrigger = functions.firestore.document('/foo/bar').onWrite(() => {
  return false;
});

VSCode launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach",
      "port": 9229,
      "restart": true,
      "skipFiles": [
        "<node_internals>/**"
      ]
    }
  ]
}

Sample Commands

$ npx firebase emulators:start --inspect-functions=12345

@googlebot googlebot added the cla: yes Manual indication that this has passed CLA. label Nov 14, 2019
@coveralls
Copy link

coveralls commented Nov 14, 2019

Coverage Status

Coverage increased (+0.2%) to 65.861% when pulling 7e9dfc2 on ss-functions-debug into e6bf37e on master.

@samtstern samtstern mentioned this pull request Nov 25, 2019
2 tasks
@samtstern samtstern marked this pull request as ready for review December 10, 2019 00:52
@samtstern
Copy link
Contributor Author

API was approved, made changes requested by council, now time for code review.

@samtstern samtstern changed the title WIP: Functions breakpoint debugging Functions breakpoint debugging Dec 10, 2019
Copy link
Contributor

@bkendall bkendall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at some of the readability/CLI stuff mostly - I'll leave the logic of emulators to more knowledgable folks.

mocha.opts Outdated Show resolved Hide resolved
src/emulator/commandUtils.ts Outdated Show resolved Hide resolved
src/emulator/commandUtils.ts Outdated Show resolved Hide resolved
src/emulator/commandUtils.ts Outdated Show resolved Hide resolved
src/emulator/controller.ts Outdated Show resolved Hide resolved
Copy link
Member

@yuchenshi yuchenshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM with major (blocking) comments regarding WorkQueue.

src/emulator/workQueue.ts Show resolved Hide resolved
src/emulator/workQueue.ts Outdated Show resolved Hide resolved
src/emulator/workQueue.ts Outdated Show resolved Hide resolved
src/test/emulators/workQueue.spec.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@bkendall bkendall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changelog please 😁

Copy link
Contributor Author

@samtstern samtstern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkendall @yuchenshi what would you expect the behavior to be if you edit code while debugging? We currently hot reload code but obviously that will require restarting the process which means killing your debugger connection. Does that seem OK?

Copy link
Member

@yuchenshi yuchenshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except the major comment about Zalgo on the test cases.

@samtstern samtstern removed the request for review from abeisgoat December 12, 2019 20:11
@dfdgsdfg
Copy link

Can I do this with firebase functions:shell? It could be super useful.

@samtstern
Copy link
Contributor Author

@dfdgsdfg we're tracking that work here:
#1872

@quantuminformation
Copy link

nice work!

@bkendall bkendall deleted the ss-functions-debug branch August 4, 2021 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Manual indication that this has passed CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't debug with firebase tools 6.10.0 in vs code due to unverified breakpoints
7 participants