Firebase-tools: FR: PubSub emulator support

Created on 25 Oct 2019  Â·  14Comments  Â·  Source: firebase/firebase-tools

I tried running cloud function locally using
Firebase emulators:start

the response i got

i Starting emulators: ["functions","database","hosting"]
âš  Your requested "node" version "8" doesn't match your global version "10"
✔ functions: Emulator started at http://localhost:5001
i database: Emulator logging to database-debug.log
✔ database: Emulator started at http://localhost:9000
i database: For testing set FIREBASE_DATABASE_EMULATOR_HOST=localhost:9000
i hosting: Serving hosting files from: public
✔ hosting: Local server: http://localhost:5000
✔ hosting: Emulator started at http://localhost:5000
i functions: Watching "/home/roc/dev/vue/ev/functions" for Cloud Functions...
i functions[scheduledFunction]: function ignored because the pubsub.googleapis.com emulator does not exist or is not running.
✔ All emulators started, it is now safe to connect.

how do i get the pubsub emulator to work locally?

emulator-suite feature request

Most helpful comment

1) You could use firebase-functions-test:
https://firebase.google.com/docs/functions/unit-testing

2) You could make an HTTP function that acts like the PubSub function for
testing. Something like this (excuse the pseudocode I'm on my phone)

exports.pubsubFn = functions.pubsub(() => {
innerFunction()
})

exports.httpTestFn = functions.https(() => {
innerFunction()
})

On Sat, Oct 26, 2019, 10:52 AM Guilherme Girotto notifications@github.com
wrote:

@samtstern https://github.com/samtstern What do you recommend to
locally test PubSub functions?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-tools/issues/1748?email_source=notifications&email_token=ACATB2TNQ5SNYPJKUEDJ7ADQQR7WJA5CNFSM4JFA6YJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECKNNEQ#issuecomment-546625170,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACATB2RBF5S3Q4BJ6XS6EBDQQR7WJANCNFSM4JFA6YJQ
.

All 14 comments

@rockyxcoded currently we don't have a PubSub emulator as part of the Firebase Emulator Suite. Even though there is a PubSub emulator as part of gcloud, it doesn't support Cloud Functions triggers so it wouldn't be very useful in this context.

I will mark this as a Feature Request for PubSub.

@samtstern What do you recommend to locally test PubSub functions together with firebase functions?

1) You could use firebase-functions-test:
https://firebase.google.com/docs/functions/unit-testing

2) You could make an HTTP function that acts like the PubSub function for
testing. Something like this (excuse the pseudocode I'm on my phone)

exports.pubsubFn = functions.pubsub(() => {
innerFunction()
})

exports.httpTestFn = functions.https(() => {
innerFunction()
})

On Sat, Oct 26, 2019, 10:52 AM Guilherme Girotto notifications@github.com
wrote:

@samtstern https://github.com/samtstern What do you recommend to
locally test PubSub functions?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-tools/issues/1748?email_source=notifications&email_token=ACATB2TNQ5SNYPJKUEDJ7ADQQR7WJA5CNFSM4JFA6YJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECKNNEQ#issuecomment-546625170,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACATB2RBF5S3Q4BJ6XS6EBDQQR7WJANCNFSM4JFA6YJQ
.

Thanks for the quick answer @samtstern!

I'd like to +1 for this feature request. Unfortunately, some of my pubsub functions are triggered by my http functions. Because of this, the solution to place the pubsub function code in a http function would require me to implement changes in other existing functions if I would want to test a chain of functions.

Because scheduled functions also work with pubsub internally, could these also be within the scope? Or would that be a separate feature request? @samtstern

How would you expect scheduled functions to work in the emulator? Let's
say you have a daily cleanup function, would you leave the emulator running
all day? Or would you want to be able to force them to run somehow.

On Mon, Oct 28, 2019, 6:56 PM Erwin AI notifications@github.com wrote:

I'd like to +1 for this feature request. Unfortunately, some of my pubsub
functions are triggered by my http functions. Because of this, the solution
to place the pubsub function code in a http function would require me to
implement changes in other existing functions.

Because scheduled functions also work with pubsub internally, could these
also be within the scope? Or would that be a separate feature request?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-tools/issues/1748?email_source=notifications&email_token=ACATB2UKKYL5WCNN3YT2V43QQ6J3XA5CNFSM4JFA6YJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECO642Q#issuecomment-547221098,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACATB2VYIKFQ7I5LATRGCG3QQ6J3XANCNFSM4JFA6YJQ
.

@samtstern From my point of view, it would be best to only allow manual triggering somehow. To have the scheduled function run on localhost as configured wouldn't make sense; that would only really allow the developer to check if the function actually triggers as configured and that doesn't seem like something you'd want to do.

@ErwinAI ok that seems reasonable.

@abeisgoat here's another FR for a future "emulator UI" panel: we should be able to manually trigger scheduled functions.

it is very simple to test schedule functions locally, it is just not clear how to do it
follow the docs

  • install firebase-tools
  • run export GOOGLE_APPLICATION_CREDENTIALS="path/to/key.json"
  • run firebase functions:shell
  • than just call your schedule function in the same console window, like scheduleFunction(), it will trigger your schedule function

@matejcsok-istvan I keep getting the error below when I run firebase functions:shell. Any idea how to solve it? Thank you.

Error: Server Error. connect ECONNREFUSED 127.0.0.1:4400

@

@matejcsok-istvan I keep getting the error below when I run firebase functions:shell. Any idea how to solve it? Thank you.

Error: Server Error. connect ECONNREFUSED 127.0.0.1:4400

Did you follow the official docs?

Yes, I am on windows. I followed the instructions for windows. Maybe, I am missing something very basic?

Yes, I am on windows. I followed the instructions for windows. Maybe, I am missing something very basic?

did you find a solution already? I'm facing the same issue

npm install --save firebase-functions@latest
npm install -g firebase-tools

this fixed it for me

Edit: After running emulator hub, it's broken again

```[debug] [2020-06-06T23:15:07.659Z] ----------------------------------------------------------------------
[debug] [2020-06-06T23:15:07.661Z] Command: C:\Program Files\nodejs\node.exe C:\Users\RobairAppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js functions:shell
[debug] [2020-06-06T23:15:07.661Z] CLI Version: 8.4.2
[debug] [2020-06-06T23:15:07.661Z] Platform: win32
[debug] [2020-06-06T23:15:07.661Z] Node Version: v10.16.0
[debug] [2020-06-06T23:15:07.662Z] Time: Sun Jun 07 2020 01:15:07 GMT+0200 (Central European Summer Time)
[debug] [2020-06-06T23:15:07.662Z] ----------------------------------------------------------------------
[debug] [2020-06-06T23:15:07.662Z]
[debug] [2020-06-06T23:15:07.670Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[debug] [2020-06-06T23:15:07.670Z] > authorizing via signed-in user
[debug] [2020-06-06T23:15:07.671Z] [iam] checking project pigeon-ac8aa for permissions ["firebase.projects.get"]
[debug] [2020-06-06T23:15:07.673Z] >>> HTTP REQUEST POST https://cloudresourcemanager.googleapis.com/v1/projects/pigeon-ac8aa:testIamPermissions
{"permissions":["firebase.projects.get"]}
[debug] [2020-06-06T23:15:08.345Z] <<< HTTP RESPONSE 200 {"content-type":"application/json; charset=UTF-8","vary":"X-Origin, Referer, Origin,Accept-Encoding","date":"Sat, 06 Jun 2020 23:15:08 GMT","server":"ESF","cache-control":"private","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","server-timing":"gfet4t7; dur=544","alt-svc":"h3-27=\":443\"; ma=2592000,h3-25=\":443\"; ma=2592000,h3-T050=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"","accept-ranges":"none","transfer-encoding":"chunked"}
[debug] [2020-06-06T23:15:08.347Z] >>> HTTP REQUEST GET http://localhost:4400/emulators

[debug] [2020-06-06T23:15:10.482Z] Error: connect ECONNREFUSED 127.0.0.1:4400
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
[error]
[error] Error: Server Error. connect ECONNREFUSED 127.0.0.1:4400
```

I added this to firebase.json
"hosting": { "port": 6000 }
run firebase emulators start in one terminal
and now firebase functions:shell works in another terminal

Was this page helpful?
0 / 5 - 0 ratings