Skip to content

test: Stabilize the masterKey TTL reload spec - #10702

Open
kokokoXUY wants to merge 1 commit into
parse-community:alphafrom
kokokoXUY:test/stable-masterkey-ttl-reload
Open

kokokoXUY wants to merge 1 commit into
parse-community:alphafrom
kokokoXUY:test/stable-masterkey-ttl-reload

Conversation

@kokokoXUY

@kokokoXUY kokokoXUY commented Sep 26, 2026 •

Copy link
Copy Markdown

Pull Request

Issue

Related to #10681 — item 3 of the tracking list (the other items are untouched).

Approach

spec/index.spec.js → should reload masterKey if ttl is set and expired configured the server with masterKeyTtl: 1 / 1000 and stubbed the spy with exactly two return values:

const masterKeySpy = jasmine.createSpy()
  .and.returnValues(Promise.resolve('firstMasterKey'), Promise.resolve('secondMasterKey'));
...
expect(masterKeySpy).toHaveBeenCalledTimes(2);

With a 1ms TTL the cached key is stale on essentially every request, so the spec depends on exactly two internal loadMasterKey() calls happening during the two save() calls. Any additional load inflates the count, exhausts the two stubs, and both assertions then fail together:

Expected spy unknown to have been called 2 times. It was called 4 times.
Expected undefined to equal 'secondMasterKey'.

That is the failure the issue reports on unrelated pull requests (an lru-cache change and an undici lock-file bump).

The spec now fakes the spy so it always produces a usable key, and asserts the property it is actually about: an expired cache is reloaded (the call count grows) and the cached value is the one produced by the last load. The 1ms TTL and the setTimeout are kept, so behaviour under test is unchanged.

Verification

Against a local MongoDB (mongodb-runner start, test database from the default URI):

original spec:  Expected spy unknown to have been called 2 times. It was called 4 times.
                Expected undefined to equal 'secondMasterKey'
                → 1 spec, 1 failure

updated spec:   → 1 spec, 0 failures

Whole file, same database, same command:

original file:  53 specs, 1 failure  (server can properly sets the push support — open connections left after the test)
updated file:   53 specs, 1 failure  (same test, same reason)

So the diff neither introduces nor hides a failure: the remaining failure is the pre-existing flaky open-connection check, and it lands on a different spec depending on the random order.

Notes and limitations, stated plainly:

  • The spec is timing-sensitive by construction, so I cannot prove it can never be flaky — only that the failure the issue describes (stub exhaustion plus a pinned call count) is removed, and that the shared fixture's leaks are untouched.
  • spec/helper.js was temporarily pointed at the local runner's port (the suite hardcodes mongodb://localhost:27017/...) and restored before this commit; the commit contains only spec/index.spec.js.
  • Only this file was run; the rest of the suite needs a database on the default port, which this host doesn't provide alongside the other work.

Tasks

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK

Summary by CodeRabbit

  • Tests
    • Updated the master-key expiration test to verify that a request after the TTL triggers another key load and returns the latest loaded key.

`should reload masterKey if ttl is set and expired` set `masterKeyTtl` to 1ms and
pinned the spy to exactly two calls backed by two stubbed return values. With a
1ms TTL the cached key is stale on essentially every request, so any additional
internal `loadMasterKey()` call inflated the count, exhausted the stubs and left
the assertions reporting `called 4 times` and `undefined` instead of the reload
the spec is about. It is a flaky failure on pull requests with unrelated diffs.

Fake the spy so it always returns a usable key, and assert the property the spec
is about: an expired cache is reloaded (the call count grows) and the cached
value is the one produced by the last load.

Verified against a local MongoDB:

- the original spec fails with
  `Expected spy unknown to have been called 2 times. It was called 4 times.` and
  `Expected undefined to equal 'secondMasterKey'`;
- the updated spec passes;
- running the whole file, both revisions report the same unrelated flaky
  `server can properly sets the push support` open-connection failure, so the
  diff adds no new failure.

Refs parse-community#10681 (item 3).
@parse-github-assistant

Copy link
Copy Markdown

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant Bot changed the title test: stabilize the masterKey TTL reload spec test: Stabilize the masterKey TTL reload spec Sep 26, 2026
@parse-github-assistant

Copy link
Copy Markdown

🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review.

Tip

  • Keep pull requests small. Large PRs will be rejected. Break complex features into smaller, incremental PRs.
  • Use Test Driven Development. Write failing tests before implementing functionality. Ensure tests pass.
  • Group code into logical blocks. Add a short comment before each block to explain its purpose.
  • We offer conceptual guidance. Coding is up to you. PRs must be merge-ready for human review.
  • Our review focuses on concept, not quality. PRs with code issues will be rejected. Use an AI agent.
  • Human review time is precious. Avoid review ping-pong. Inspect and test your AI-generated code.

Note

Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect.

Caution

Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code.

@kokokoXUY

Copy link
Copy Markdown
Author

Ready for review.

Scope: item 3 of #10681. The spec no longer pins the spy to exactly two calls backed by two stubbed return values; it fakes the spy so every load produces a usable key and asserts what the spec is about — an expired cache is reloaded, and the cached value is the one from the last load. The 1ms TTL and the setTimeout are unchanged.

Checked before submitting, against a local MongoDB:

  • the original spec fails with Expected spy unknown to have been called 2 times. It was called 4 times. and Expected undefined to equal 'secondMasterKey'; the updated spec passes;
  • running the whole file, both revisions report the same unrelated flaky server can properly sets the push support open-connection failure, so the diff hides nothing.

What I could not check: the rest of the suite, which needs a database on the default port that this host does not provide. The spec stays timing-sensitive by construction; what is removed is the stub exhaustion plus pinned call count the issue describes.

Prepared with an AI coding agent and reviewed before submission.

@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 4d83de33-908f-4b11-a100-648c71356609

📥 Commits

Reviewing files that changed from the base of the PR and between 82792be and 352413b.

📒 Files selected for processing (1)
  • spec/index.spec.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The master-key TTL test now generates a distinct key for each load. After the TTL, it checks that another load occurred and that the cached key matches the latest load.

Changes

Master-key TTL test

Layer / File(s) Summary
TTL reload and cache assertions
spec/index.spec.js
The spy returns a key labeled with its call count. After waiting past the TTL, the test checks for an additional load and confirms that the cached key matches the latest load.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 35241

The update makes the TTL test tolerate extra internal key loads while still checking reload and cache behavior. No concrete merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 7
✅ Passed checks (7 passed)
Check name Status Explanation
Title check ✅ Passed The title begins with the required test: prefix, and the first letter after the prefix is capitalized. It clearly describes the test stabilization change.
Description check ✅ Passed The description includes the required Pull Request, Issue, Approach, Verification, and Tasks sections. It explains the change, test results, limitations, and completed tasks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Check ✅ Passed PASS — The pull request changes only spec/index.spec.js; it does not change production code, dependencies, authentication logic, or configuration handling. The added code uses a Jasmine fake and det…
Engage In Review Feedback ✅ Passed No review feedback comments or actionable findings were supplied. Therefore, there was no feedback for the user to ignore, resolve, or address without discussion.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@kokokoXUY

Copy link
Copy Markdown
Author

Stability evidence on this head, added after the earlier runs.

The updated spec was run five times in a row against a local MongoDB on the same revision:

run 1: 1 spec, 0 failure
run 2: 1 spec, 0 failure
run 3: 1 spec, 0 failure
run 4: 1 spec, 0 failure
run 5: 1 spec, 0 failure

For contrast, the original spec failed on its first run in the same environment with:

Expected spy unknown to have been called 2 times. It was called 4 times.
Expected undefined to equal 'secondMasterKey'.

The reload the spec is about is still exercised — the call count grows and the cached value tracks the last load — only the pinned count and the two-value stub are gone.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant