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: rewrite createreadstream tests #1401

Open
wants to merge 15 commits into
base: move-retries-to-google-gax
Choose a base branch
from

Conversation

danieljbruce
Copy link
Contributor

@danieljbruce danieljbruce commented Apr 12, 2024

When retries are moved to google-gax from the handwritten layer of nodejs-bigtable then the current tests mentioned in the PR will not work. They need to be rewritten to still test retry behavior, but account for the fact that the retries will be done in a different layer.

Here is what is done to modify Tests in [read-rows.ts] just to clarify further:

  1. This sinon stub mock currently mocks out the request function and sends responses back to createreadstream where retries are currently done. Since retries will not be done in createreadstream anymore and this test intends to test retries then responses must be mocked in a layer below where retries are going to be done in google-gax in a later change. The current sinon stub mock should be removed and instead the mock grpc server should send responses back in order to test retry behavior.
  2. As is done with the current mock, the new mock server mock should check each request to ensure it matches request_options

- Transform the rowsLimit parameter into an integer
- Change the hook into a before hook so that we don’t attempt to create multiple mock servers
- Create a guard so that the stream only writes if there are row keys to write
define new interfaces too
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: bigtable Issues related to the googleapis/nodejs-bigtable API. labels Apr 12, 2024
@danieljbruce danieljbruce marked this pull request as ready for review April 12, 2024 19:43
@danieljbruce danieljbruce requested review from a team as code owners April 12, 2024 19:43
Copy link
Contributor Author

@danieljbruce danieljbruce left a comment

Choose a reason for hiding this comment

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

Added a few explanations throughout the PR

@@ -37,7 +37,6 @@ export class MockServer {
`localhost:${this.port}`,
grpc.ServerCredentials.createInsecure(),
() => {
server.start();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now deprecated. grpc servers don't need to be started explicitly.

const {tests} = require('../../system-test/data/read-rows-retry-test.json') as {
tests: Test[];
tests: ReadRowsTest[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Test interface responses actually don't line up with what ReadRow responses should be so we define new interfaces that correctly match the structure of this data.

}
}

function rowResponse(rowKey: {}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A response from the server is modified slightly to match what a response would be from the request layer which explains the changes in this function.

};
}

function getRequestOptions(request: any): google.bigtable.v2.IRowSet {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the old test, this contains all the code which was used for building a request.

0,
'not all the responses were used'
);
assert.deepStrictEqual(requestedOptions, test.request_options);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These asserts are moved into checkResults which evaluates response/request data when the call to createreadstream results in an error or ended stream.

@danieljbruce danieljbruce added the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 12, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 12, 2024
@danieljbruce danieljbruce added the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 16, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 16, 2024
@danieljbruce danieljbruce changed the base branch from main to move-retries-to-google-gax April 16, 2024 20:09
if (request.rows && request.rows.rowRanges) {
requestOptions.rowRanges = request.rows.rowRanges.map(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(range: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there another type option than any that can be used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. I made this more specific and solved the resulting compiler errors too.

);
}
if (request.rows && request.rows.rowKeys) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there another type we can use besides any?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got rid of this comment and made it compile. This was copy/paste from the original test along with some other any's. Now the types are more specific, but a lot of interfaces and guards needed to be added to solve compiler errors up and down the stack.

// shorter.
if (request.rowsLimit && request.rowsLimit !== '0') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(requestOptions as any).rowsLimit = parseInt(request.rowsLimit);
Copy link
Contributor

Choose a reason for hiding this comment

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

once again asking about the any 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one was a good one to fix. Helped catch some incorrect types downstream.

}
if (response.end_with_error) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const error: any = new Error();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this an error coming from the server? If so is it a GoogleError not an any?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. Changed to GoogleError.

Comment on lines 51 to 69
interface CreateReadStreamResponse {
row_keys?: string[];
end_with_error?: 4;
}

interface CreateReadStreamRequest {
rowKeys: string[];
rowRanges: google.bigtable.v2.IRowRange[];
rowsLimit?: number;
}
export interface ReadRowsTest {
createReadStream_options?: GetRowsOptions;
max_retries: number;
responses: CreateReadStreamResponse[];
request_options: CreateReadStreamRequest[];
error: number;
row_keys_read: string[][];
name: string;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In here there is an interesting mix of snake_case and camelCase - is there a reason why both have to be used? Or can they all be migrated to a more typical JS-y camelCase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They can be migrated, but it means that the json file containing all the test data in

"createReadStream_options": {
needs to be updated to match.

@leahecole
Copy link
Contributor

Is the failure of the conformance tests expected?

@danieljbruce
Copy link
Contributor Author

Is the failure of the conformance tests expected?

Yup. Right now the conformance tests are supposed to be running, but a whole bunch of them fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the googleapis/nodejs-bigtable API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants