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
base: move-retries-to-google-gax
Are you sure you want to change the base?
test: rewrite createreadstream tests #1401
Conversation
- 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
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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[]; |
There was a problem hiding this comment.
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: {}) { |
There was a problem hiding this comment.
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.
system-test/read-rows.ts
Outdated
}; | ||
} | ||
|
||
function getRequestOptions(request: any): google.bigtable.v2.IRowSet { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
system-test/read-rows.ts
Outdated
if (request.rows && request.rows.rowRanges) { | ||
requestOptions.rowRanges = request.rows.rowRanges.map( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(range: any) => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
system-test/read-rows.ts
Outdated
); | ||
} | ||
if (request.rows && request.rows.rowKeys) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
system-test/read-rows.ts
Outdated
// shorter. | ||
if (request.rowsLimit && request.rowsLimit !== '0') { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(requestOptions as any).rowsLimit = parseInt(request.rowsLimit); |
There was a problem hiding this comment.
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
🙂
There was a problem hiding this comment.
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.
system-test/read-rows.ts
Outdated
} | ||
if (response.end_with_error) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const error: any = new Error(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Changed to GoogleError.
system-test/testTypes.ts
Outdated
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; | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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": { |
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. |
It was necessary to add guards to make this work. Also changed the error type to Google error.
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: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.