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 parameter change cache miss #17346

Merged
merged 1 commit into from
Jan 26, 2023

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Jan 23, 2023

Tests have been added to ensure that our middleware will not return a cached response to a request with unique parameters. Each parameter supported by each method is tested independently.

Closes #17003

Manual Testing Steps

No functional changes.

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

{
name: 'eth_call',
blockParamIndex: 1,
numberOfParameters: 2,
Copy link
Member Author

Choose a reason for hiding this comment

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

I looked up each method in both the Ethereum JSON-RPC spec, and the Infura docs. I ensured the configured number of parameters matched the maximum shown in either docs.

They mostly matched already; I think there was a single method that had one less parameter on Infura because it didn't support some option, don't recall which one. And there were some methods exclusive to one or the other. But other than that they matched.

Tests have been added to ensure that our middleware will not return a
cached response to a request with unique parameters. Each parameter
supported by each method is tested independently.

Closes #17003
@Gudahtt Gudahtt force-pushed the add-tests-to-ensure-cache-miss-when-param-changes branch from ad3f591 to 21004bb Compare January 23, 2023 15:33
@Gudahtt Gudahtt marked this pull request as ready for review January 23, 2023 15:39
@Gudahtt Gudahtt requested a review from a team as a code owner January 23, 2023 15:39
@metamaskbot
Copy link
Collaborator

Builds ready [21004bb]
Page Load Metrics (1262 ± 96 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint101170124199
domContentLoaded104217961252208100
load10681796126220196
domInteractive104217961252208100
Bundle size diffs
  • background: 0 bytes
  • ui: 0 bytes
  • common: 0 bytes

});
});
},
);
});

describe('methods that assume there is no block param', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this isn't the target of this PR so this is more of just an observation/question: this seems like an odd way to categorize the methods for testing?

Copy link
Member Author

Choose a reason for hiding this comment

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

These groups are meant to reflect the caching strategies used in our middleware: either we ignore the method, or we cache it by the current block, or we cache it by the referenced block.

This "assume there is no block param" group is for methods that we cache by block, where the middleware doesn't bother looking for any block reference in the method parameters.

Copy link
Member Author

Choose a reason for hiding this comment

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

Definitely lots of room for improvement with how these are organized. We can describe these categories better, and deduplicate the common behavior more effectively.

@@ -452,6 +495,46 @@ export function testsForRpcMethodAssumingNoBlockParam(
});
});

for (const paramIndex of [...Array(numberOfParameters).keys()]) {
it(`does not reuse the result of a previous request if parameter at index "${paramIndex}" differs`, async () => {
Copy link
Contributor

@adonesky1 adonesky1 Jan 25, 2023

Choose a reason for hiding this comment

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

Took me a while to work through why this was testing what you claim its testing. But I see now! Looks good!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah... the param builder function didn't quite do what I wanted here, so I constructed the parameters inline in the test. I should probably find a way to make this more readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Would you mind explaining which part you initially found confusing? That might help in finding a clearer way to write this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there's any issue with the description. I think it was just towards the end of my day and my brain wasn't working as well. So I guess this comment was more for me and not very generalizable 😅

Comment on lines +1694 to +1697
if (paramIndex === blockParamIndex) {
// testing changes in block param is covered under later tests
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not understanding why we want to skip these cases for this case?

Copy link
Member Author

@Gudahtt Gudahtt Jan 26, 2023

Choose a reason for hiding this comment

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

These tests are basically meant to ensure that the middleware correctly recognizes any parameter changes, and doesn't return a cached response that was generated with different params. We want to check this for the block parameter as well, but, that one isn't so simple to make an arbitrary mutation to. The change will have other side-effects because the value is used by the caching middleware in other ways (it determines which block cache to use).

We do want to test the case where the block reference changes too, but, this test is within the block:

describe.each([
  ['given no block tag', undefined],
  ['given a block tag of "latest"', 'latest'],
])`

i.e. the block reference is always set to a static value in this test, that's what this category is for.

The case where the block reference is changed is covered by the test "does not reuse the result of a previous request if it was made with different arguments than this one", about ~1300 lines below here.

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

Just one real question, though I'm probably just not understanding something. Otherwise LGTM

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM!

@Gudahtt Gudahtt merged commit 001ea4c into develop Jan 26, 2023
@Gudahtt Gudahtt deleted the add-tests-to-ensure-cache-miss-when-param-changes branch January 26, 2023 15:57
@github-actions github-actions bot locked and limited conversation to collaborators Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants