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

test(rtdb-limit-child-nodes): use emulator for testing #482

Closed
wants to merge 4 commits into from

Conversation

russellwheatley
Copy link
Member

@russellwheatley russellwheatley commented Nov 3, 2020

WIP

notes

  • path property on Reference is deprecated so it has been removed.

@google-cla google-cla bot added the cla: yes Author has signed the CLA label Nov 3, 2020
@russellwheatley russellwheatley added this to Under consideration in Extension Update Tracker via automation Nov 3, 2020
@russellwheatley russellwheatley moved this from Under consideration to Implementation in progress in Extension Update Tracker Nov 3, 2020
@thatfiredev
Copy link
Member

I think functions.handler.database is required for a Cloud Function to be deployed as an extension. I'm afraid we won't be able to deploy it with functions.database.

@russellwheatley
Copy link
Member Author

Hey, thanks for the update, @rosariopfernandes. Could you confirm that this is the case, @jhuleatt? I've created an issue here for this issue either way.

@russellwheatley russellwheatley moved this from Implementation in progress to Blocked in Extension Update Tracker Nov 4, 2020
@joehan
Copy link
Collaborator

joehan commented Nov 6, 2020

Apologies for the slow response here, this slipped past me. To give some clarity on the extensions emualtor:

  • The 'normal' namespace (functions.database.ref.onCreate) defines a trigger and a handler, whereas the handler namespace (functions.handler.database.ref.onCreate) only defines a handler. You CAN use the normal namespace for extensions - however, the trigger defined by the code will be ignored in favor of the trigger defined in extension.yaml. This is a bit confusing, so we use the handler namespace to avoid defining a trigger in the code that will be ignored.

  • Because it doesn't define any triggers, the handler namespace won't work with firebase emulators:exec or firebase emulators:start. Instead, use firebase ext:dev:emulators:exec <path/to/extension.yaml> or firebase ext:dev:emulators:start <path/to/extension.yaml> - this will pick up triggers from the extension.yaml.

Hopefully this helps - if the ext:dev:emulator:* commands still aren't working, this is likely a regression and I will look into this further

@russellwheatley
Copy link
Member Author

Hey @joehan, thanks for the update! I was indeed using the wrong command (i.e. firebase emulators:start). I am encountering another problem. If I run this command:

firebase ext:dev:emulators:start ./extension.yaml --test-params=emulator-params.env --project=extensions-testing

from the rtdb-limit-child-nodes extension package root, nothing happens.

I also tried without the path in the command:

firebase ext:dev:emulators:start --test-params=emulator-params.env --project=extensions-testing

Which gave me the following error:

Error: HTTP Error: 403, Invalid Firebase database name

My emulator-params.env file looks like this:

LOCATION=europe-west2
MAX_COUNT=2
NODE_PATH=test_path

@jhuleatt
Copy link
Collaborator

jhuleatt commented Nov 9, 2020

@russellwheatley @joehan it looks like the emulator doesn't support the ${param:PARAM} syntax introduced in #457. If I change back to the ${PARAM} syntax where the RTDB event trigger is defined in extension.yaml, the emulator starts up without issue with this command:

firebase ext:dev:emulators:start --test-params=emulator-params.env --project=jeff-test-699d3

I'll commit my extension.yaml changes, since we probably don't want to block this on CLI updates. The CLI doesn't seem to have full support for the new syntax - a similar bug recently bit me on another PR #486 (comment)

Googlers, I've filed internal issue number 172862340 to fix the ${param:PARAM} issue on the platform side.

@google-cla

This comment has been minimized.

@google-cla google-cla bot added cla: no Author has not signed the CLA. and removed cla: yes Author has signed the CLA labels Nov 9, 2020
@@ -55,7 +55,7 @@ resources:
runtime: nodejs10
eventTrigger:
eventType: providers/google.firebase.database/eventTypes/ref.create
resource: projects/_/instances/${param:DATABASE_INSTANCE}/refs/${param:NODE_PATH}/{messageid}
resource: projects/_/instances/${DATABASE_INSTANCE}/refs/${NODE_PATH}/{messageid}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@russellwheatley @joehan this is what I had to change to get it to work

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahh, that makes a lot of sense! I'll take on the CLI bug this week to unblock the change

@jhuleatt

This comment has been minimized.

@google-cla google-cla bot added cla: yes Author has signed the CLA and removed cla: no Author has not signed the CLA. labels Nov 9, 2020
@jhuleatt jhuleatt moved this from Blocked to Implementation in progress in Extension Update Tracker Nov 9, 2020
@jhuleatt
Copy link
Collaborator

jhuleatt commented Nov 9, 2020

Update:

I can visit http://localhost:4000/ to see the emulator UI and manually add data to the emulated database. However, when the function runs, I seem to run into something like firebase/firebase-functions#726, so I can't get it to fully work. Here's the error (firebase-tools 8.15.1):

Error when truncating the database node Error: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com 
    at fatal (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/@firebase/database/dist/index.node.cjs.js:341:11)
    at parseRepoInfo (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/@firebase/database/dist/index.node.cjs.js:1294:9)
    at RepoManager.databaseFromApp (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/@firebase/database/dist/index.node.cjs.js:14995:25)
    at Object.initStandalone (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/@firebase/database/dist/index.node.cjs.js:15396:45)
    at DatabaseService.getDatabase (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/firebase-admin/lib/database/database.js:66:23)
    at FirebaseApp.database (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/firebase-admin/lib/firebase-app.js:231:24)
    at DataSnapshot.get ref [as ref] (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/firebase-functions/lib/providers/database.js:293:34)
    at /Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/lib/index.js:38:36
    at cloudFunction (/Users/jhuleatt/git/extensions/rtdb-limit-child-nodes/functions/node_modules/firebase-functions/lib/cloud-functions.js:134:23)
    at /Users/jhuleatt/.nvm/versions/node/v14.3.0/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:601:20

@joehan is it possible the extensions emulators use a different codepath that needs a fix similar to the one that fixed firebase/firebase-functions#726 ?


const configPath = cleanPath(config.nodePath);

export const rtdblimit = functions.database.ref(`${configPath}/{nodeId}`).onCreate(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please change back to functions.handler. We'd like to make sure the extensions emulator commands work correctly

@jhuleatt jhuleatt moved this from Implementation in progress to Blocked in Extension Update Tracker Nov 10, 2020
@jhuleatt jhuleatt moved this from Blocked to Implementation in progress in Extension Update Tracker Nov 16, 2020
@jhuleatt
Copy link
Collaborator

The bug blocking this was fixed in firebase-tools 8.16.0

@russellwheatley
Copy link
Member Author

Thanks for the update, @jhuleatt. I'll get this revised 👍

@russellwheatley
Copy link
Member Author

russellwheatley commented Nov 18, 2020

Hey @jhuleatt @joehan, I'm unable to get this working. My setup:

  • firebase-tools version 8.16.2,
  • firebase-functions version 3.11.0 as suggested here.
  • pulled in Jeff's PARAM changes
  • running firebase ext:dev:emulators:start --test-params=emulator-params.env --project=extensions-testing

When I add data via the console UI, I get the same error as mentioned above:

>  [2020-11-18T16:23:44.801Z]  @firebase/database: FIREBASE FATAL ERROR: Cannot 
parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com >  {"sever
ity":"ERROR","message":"Error when truncating the database node Error: FIREBASE 
FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.fireb
aseio.com \n    at fatal (/Users/russellwheatley/projects/extensions/rtdb-limit-
child-nodes/functions/node_modules/@firebase/database/dist/index.node.cjs.js:341
:11)\n    at parseRepoInfo (/Users/russellwheatley/projects/extensions/rtdb-limi
t-child-nodes/functions/node_modules/@firebase/database/dist/index.node.cjs.js:1
296:9)\n    at RepoManager.databaseFromApp (/Users/russellwheatley/projects/exte
nsions/rtdb-limit-child-nodes/functions/node_modules/@firebase/database/dist/ind
ex.node.cjs.js:15004:25)\n    at Object.initStandalone (/Users/russellwheatley/p
rojects/extensions/rtdb-limit-child-nodes/functions/node_modules/@firebase/datab
ase/dist/index.node.cjs.js:15395:45)\n    at DatabaseService.getDatabase (/Users
/russellwheatley/projects/extensions/rtdb-limit-child-nodes/functions/node_modul
es/firebase-admin/lib/database/database.js:66:23)\n    at FirebaseApp.database (
/Users/russellwheatley/projects/extensions/rtdb-limit-child-nodes/functions/node
_modules/firebase-admin/lib/firebase-app.js:231:24)\n    at DataSnapshot.get ref
 [as ref] (/Users/russellwheatley/projects/extensions/rtdb-limit-child-nodes/fun
ctions/node_modules/firebase-functions/lib/providers/database.js:293:34)\n    at
 /Users/russellwheatley/projects/extensions/rtdb-limit-child-nodes/functions/lib
/index.js:30:36\n    at cloudFunction (/Users/russellwheatley/projects/extension
s/rtdb-limit-child-nodes/functions/node_modules/firebase-functions/lib/cloud-fun
ctions.js:134:23)\n    at /Users/russellwheatley/.nvm/versions/node/v12.13.0/lib
/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:609:20"}

The exact moment it happens is when snapshot.ref getter is invoked. Using snapshot.key for example, will not cause an error.

@jhuleatt jhuleatt moved this from Implementation in progress to Blocked in Extension Update Tracker Nov 23, 2020
@russellwheatley
Copy link
Member Author

Issues raised with firebase-tools blocking PR:
firebase/firebase-tools#2928
firebase/firebase-tools#2930

@cabljac
Copy link
Contributor

cabljac commented Feb 13, 2023

going to close this for now as it's pretty old, would be easier to add tests in a new PR i think.

@cabljac cabljac closed this Feb 13, 2023
Extension Update Tracker automation moved this from Blocked to Closed Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Author has signed the CLA
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants