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

fix: do not use gaxServerStreamingRetries for bidi or client streaming #1575

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,41 @@ describe('v1beta1.BigQueryStorageClient', () => {
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes readRows without error and gaxServerStreamingRetries enabled', async () => {
const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({gaxServerStreamingRetries: true});
client.initialize();
const request = generateSampleMessage(
new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest()
);
request.readPosition ??= {};
request.readPosition.stream ??= {};
const defaultValue1 =
getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest', ['readPosition', 'stream', 'name']);
request.readPosition.stream.name = defaultValue1;
const expectedHeaderRequestParams = `read_position.stream.name=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse()
);
client.innerApiCalls.readRows = stubServerStreamingCall(expectedResponse);
const stream = client.readRows(request);
const promise = new Promise((resolve, reject) => {
stream.on('data', (response: protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse) => {
resolve(response);
});
stream.on('error', (err: Error) => {
reject(err);
});
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
const actualRequest = (client.innerApiCalls.readRows as SinonStub)
.getCall(0).args[0];
assert.deepStrictEqual(actualRequest, request);
const actualHeaderRequestParams = (client.innerApiCalls.readRows as SinonStub)
.getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes readRows with error', async () => {
const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
Expand Down Expand Up @@ -800,6 +835,12 @@ describe('v1beta1.BigQueryStorageClient', () => {
});
await assert.rejects(promise, expectedError);
});
it('should create a client with gaxServerStreamingRetries enabled', () => {
const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({
gaxServerStreamingRetries: true,
});
assert(client);
});
});

describe('Path templates', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,41 @@ describe('v1beta1.BigQueryStorageClient', () => {
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes readRows without error and gaxServerStreamingRetries enabled', async () => {
const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({gaxServerStreamingRetries: true});
client.initialize();
const request = generateSampleMessage(
new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest()
);
request.readPosition ??= {};
request.readPosition.stream ??= {};
const defaultValue1 =
getTypeDefaultValue('.google.cloud.bigquery.storage.v1beta1.ReadRowsRequest', ['readPosition', 'stream', 'name']);
request.readPosition.stream.name = defaultValue1;
const expectedHeaderRequestParams = `read_position.stream.name=${defaultValue1}`;
const expectedResponse = generateSampleMessage(
new protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse()
);
client.innerApiCalls.readRows = stubServerStreamingCall(expectedResponse);
const stream = client.readRows(request);
const promise = new Promise((resolve, reject) => {
stream.on('data', (response: protos.google.cloud.bigquery.storage.v1beta1.ReadRowsResponse) => {
resolve(response);
});
stream.on('error', (err: Error) => {
reject(err);
});
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
const actualRequest = (client.innerApiCalls.readRows as SinonStub)
.getCall(0).args[0];
assert.deepStrictEqual(actualRequest, request);
const actualHeaderRequestParams = (client.innerApiCalls.readRows as SinonStub)
.getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes readRows with error', async () => {
const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
Expand Down Expand Up @@ -791,6 +826,12 @@ describe('v1beta1.BigQueryStorageClient', () => {
});
await assert.rejects(promise, expectedError);
});
it('should create a client with gaxServerStreamingRetries enabled', () => {
const client = new bigquerystorageModule.v1beta1.BigQueryStorageClient({
gaxServerStreamingRetries: true,
});
assert(client);
});
});

describe('Path templates', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class EchoClient {
// Provide descriptors for these.
this.descriptors.stream = {
expand: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.SERVER_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
collect: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.CLIENT_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
collect: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.CLIENT_STREAMING, !!opts.fallback),
chat: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class MessagingClient {
// Provide descriptors for these.
this.descriptors.stream = {
streamBlurbs: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.SERVER_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
sendBlurbs: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.CLIENT_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
sendBlurbs: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.CLIENT_STREAMING, !!opts.fallback),
connect: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,29 @@ describe('v1beta1.EchoClient', () => {
assert.deepStrictEqual(response, expectedResponse);
});

it('invokes expand without error and gaxServerStreamingRetries enabled', async () => {
const client = new echoModule.v1beta1.EchoClient({gaxServerStreamingRetries: true});
client.initialize();
const request = generateSampleMessage(
new protos.google.showcase.v1beta1.ExpandRequest()
);
const expectedResponse = generateSampleMessage(
new protos.google.showcase.v1beta1.EchoResponse()
);
client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse);
const stream = client.expand(request);
const promise = new Promise((resolve, reject) => {
stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => {
resolve(response);
});
stream.on('error', (err: Error) => {
reject(err);
});
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
});

it('invokes expand with error', async () => {
const client = new echoModule.v1beta1.EchoClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
Expand Down Expand Up @@ -716,6 +739,12 @@ describe('v1beta1.EchoClient', () => {
});
await assert.rejects(promise, expectedError);
});
it('should create a client with gaxServerStreamingRetries enabled', () => {
const client = new echoModule.v1beta1.EchoClient({
gaxServerStreamingRetries: true,
});
assert(client);
});
});

describe('chat', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,39 @@ describe('v1beta1.MessagingClient', () => {
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes streamBlurbs without error and gaxServerStreamingRetries enabled', async () => {
const client = new messagingModule.v1beta1.MessagingClient({gaxServerStreamingRetries: true});
client.initialize();
const request = generateSampleMessage(
new protos.google.showcase.v1beta1.StreamBlurbsRequest()
);
const defaultValue1 =
getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']);
request.name = defaultValue1;
const expectedHeaderRequestParams = `name=${defaultValue1 ?? '' }`;
const expectedResponse = generateSampleMessage(
new protos.google.showcase.v1beta1.StreamBlurbsResponse()
);
client.innerApiCalls.streamBlurbs = stubServerStreamingCall(expectedResponse);
const stream = client.streamBlurbs(request);
const promise = new Promise((resolve, reject) => {
stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => {
resolve(response);
});
stream.on('error', (err: Error) => {
reject(err);
});
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub)
.getCall(0).args[0];
assert.deepStrictEqual(actualRequest, request);
const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub)
.getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes streamBlurbs with error', async () => {
const client = new messagingModule.v1beta1.MessagingClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
Expand Down Expand Up @@ -1364,6 +1397,12 @@ describe('v1beta1.MessagingClient', () => {
});
await assert.rejects(promise, expectedError);
});
it('should create a client with gaxServerStreamingRetries enabled', () => {
const client = new messagingModule.v1beta1.MessagingClient({
gaxServerStreamingRetries: true,
});
assert(client);
});
});

describe('connect', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class EchoClient {
// Provide descriptors for these.
this.descriptors.stream = {
expand: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.SERVER_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
collect: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.CLIENT_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
collect: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.CLIENT_STREAMING, !!opts.fallback),
chat: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class MessagingClient {
// Provide descriptors for these.
this.descriptors.stream = {
streamBlurbs: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.SERVER_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
sendBlurbs: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.CLIENT_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
sendBlurbs: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.CLIENT_STREAMING, !!opts.fallback),
connect: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,29 @@ describe('v1beta1.EchoClient', () => {
assert.deepStrictEqual(response, expectedResponse);
});

it('invokes expand without error and gaxServerStreamingRetries enabled', async () => {
const client = new echoModule.v1beta1.EchoClient({gaxServerStreamingRetries: true});
client.initialize();
const request = generateSampleMessage(
new protos.google.showcase.v1beta1.ExpandRequest()
);
const expectedResponse = generateSampleMessage(
new protos.google.showcase.v1beta1.EchoResponse()
);
client.innerApiCalls.expand = stubServerStreamingCall(expectedResponse);
const stream = client.expand(request);
const promise = new Promise((resolve, reject) => {
stream.on('data', (response: protos.google.showcase.v1beta1.EchoResponse) => {
resolve(response);
});
stream.on('error', (err: Error) => {
reject(err);
});
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
});

it('invokes expand with error', async () => {
const client = new echoModule.v1beta1.EchoClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
Expand Down Expand Up @@ -707,6 +730,12 @@ describe('v1beta1.EchoClient', () => {
});
await assert.rejects(promise, expectedError);
});
it('should create a client with gaxServerStreamingRetries enabled', () => {
const client = new echoModule.v1beta1.EchoClient({
gaxServerStreamingRetries: true,
});
assert(client);
});
});

describe('chat', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,39 @@ describe('v1beta1.MessagingClient', () => {
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes streamBlurbs without error and gaxServerStreamingRetries enabled', async () => {
const client = new messagingModule.v1beta1.MessagingClient({gaxServerStreamingRetries: true});
client.initialize();
const request = generateSampleMessage(
new protos.google.showcase.v1beta1.StreamBlurbsRequest()
);
const defaultValue1 =
getTypeDefaultValue('.google.showcase.v1beta1.StreamBlurbsRequest', ['name']);
request.name = defaultValue1;
const expectedHeaderRequestParams = `name=${defaultValue1}`;
const expectedResponse = generateSampleMessage(
new protos.google.showcase.v1beta1.StreamBlurbsResponse()
);
client.innerApiCalls.streamBlurbs = stubServerStreamingCall(expectedResponse);
const stream = client.streamBlurbs(request);
const promise = new Promise((resolve, reject) => {
stream.on('data', (response: protos.google.showcase.v1beta1.StreamBlurbsResponse) => {
resolve(response);
});
stream.on('error', (err: Error) => {
reject(err);
});
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
const actualRequest = (client.innerApiCalls.streamBlurbs as SinonStub)
.getCall(0).args[0];
assert.deepStrictEqual(actualRequest, request);
const actualHeaderRequestParams = (client.innerApiCalls.streamBlurbs as SinonStub)
.getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes streamBlurbs with error', async () => {
const client = new messagingModule.v1beta1.MessagingClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
Expand Down Expand Up @@ -1355,6 +1388,12 @@ describe('v1beta1.MessagingClient', () => {
});
await assert.rejects(promise, expectedError);
});
it('should create a client with gaxServerStreamingRetries enabled', () => {
const client = new messagingModule.v1beta1.MessagingClient({
gaxServerStreamingRetries: true,
});
assert(client);
});
});

describe('connect', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class EchoClient {
// Provide descriptors for these.
this.descriptors.stream = {
expand: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.SERVER_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
collect: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.CLIENT_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
collect: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.CLIENT_STREAMING, !!opts.fallback),
chat: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class MessagingClient {
// Provide descriptors for these.
this.descriptors.stream = {
streamBlurbs: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.SERVER_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
sendBlurbs: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.CLIENT_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries),
sendBlurbs: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.CLIENT_STREAMING, !!opts.fallback),
connect: new this._gaxModule.StreamDescriptor(this._gaxModule.StreamType.BIDI_STREAMING, !!opts.fallback, !!opts.gaxServerStreamingRetries)
};

Expand Down
Loading
Loading