Skip to content

Allow failing of individual transactions #3052

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

Merged
merged 3 commits into from
May 13, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

Disclaimer: This is pretty ugly... feedback appreciated :)

The idea of the PR is to expand the new "failDatabase" spec test feature to allow the tests to specify which transaction action to fail. This allows individualized failures for operations that spawn multiple actions. Currently, we only test scenarios where the first transaction fails. This will allows us to test what happens if the first transaction succeeds and the second one fails.

@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/individualfailures branch from 16db9ba to 2d869e5 Compare May 12, 2020 04:20
@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 12, 2020

Binary Size Report

Affected SDKs

  • @firebase/database

    Type Base (a57dac5) Head (91a359b) Diff
    browser 268 kB 268 kB +74 B (+0.0%)
    esm2017 235 kB 235 kB +76 B (+0.0%)
    main 269 kB 269 kB +74 B (+0.0%)
    module 266 kB 266 kB +74 B (+0.0%)
  • @firebase/firestore

    Type Base (a57dac5) Head (91a359b) Diff
    browser 249 kB 249 kB -74 B (-0.0%)
    esm2017 194 kB 194 kB -66 B (-0.0%)
    main 490 kB 490 kB -293 B (-0.1%)
    module 247 kB 247 kB -74 B (-0.0%)
  • @firebase/firestore/memory

    Type Base (a57dac5) Head (91a359b) Diff
    browser 190 kB 190 kB -2 B (-0.0%)
    esm2017 148 kB 148 kB -16 B (-0.0%)
    main 367 kB 366 kB -118 B (-0.0%)
    module 188 kB 188 kB -2 B (-0.0%)
  • firebase

    Type Base (a57dac5) Head (91a359b) Diff
    firebase-database.js 187 kB 187 kB +42 B (+0.0%)
    firebase-firestore.js 288 kB 288 kB -80 B (-0.0%)
    firebase-firestore.memory.js 230 kB 230 kB -5 B (-0.0%)
    firebase.js 821 kB 821 kB -38 B (-0.0%)

Test Logs

);
} else {
return super.runTransaction(action, mode, transactionOperation);
if (this.injectFailures[action as PersistenceAction] === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider saving the result of this.injectFailures[action as PersistenceAction] to a local variable instead of accessing it twice via this long dictionary access syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
if (this.injectFailures[action as PersistenceAction]) {
return Promise.reject(
new IndexedDbTransactionError(new Error('Simulated retryable error'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider including the value of action in the error message. This may assist with debugging to figure out which action caused the exception to be thrown.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Future me will thank you as I am debugging test assertions.

);
} else {
return super.runTransaction(action, mode, transactionOperation);
if (this.injectFailures[action as PersistenceAction] === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this block of code is an identical copy/paste from above, then consider moving it to a helper function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not identical because I only updated one of the two blocks to use "else if". But it should be identical... Moved it to a helper function.

);
} else {
return super.runTransaction(action, mode, transactionOperation);
if (this.injectFailures[action as PersistenceAction] === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the Android and iOS spec test framework will need to be updated to handle this change in the generated JSON. Are you planning to do that as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we need to make those changes there too. For now, the "recovery" tests are marked no-ios and no-android. We won't need to update the runner until we remove these tags and implement LevelDB/SQLite recovery.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh you're right. I missed the no-ios and no-android tags... even though I was looking for them 🤔

throw fail('Failure mode not specified for action: ' + action);
} else if (shouldFail) {
throw new IndexedDbTransactionError(
new Error('Simulated retryable error' + action)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Add a space or colon after "error" so that the action text is not mashed into the word "error".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a nit but a crucial typo fix :) Done

);
} else {
return super.runTransaction(action, mode, transactionOperation);
if (this.injectFailures[action as PersistenceAction] === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh you're right. I missed the no-ios and no-android tags... even though I was looking for them 🤔

@schmidt-sebastian schmidt-sebastian merged commit 425dfb1 into master May 13, 2020
@firebase firebase locked and limited conversation to collaborators Jun 13, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/individualfailures branch November 9, 2020 22:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants