Skip to content

Commit 2fdf98f

Browse files
authored
fix: Conformance test sample rowkeys generic deadline (#1562)
* clean up server deprecated code * test passes now with changes to test proxy * remove passing test * remove await * fix sync repo settings * grab app profileId from client * remove passing test * changes to timeout * fix deadline error * remove package.json line * fix prettier issues * remove old functions for deadline * Update bulk-mutate-rows.js * Update read-rows.js * Update read-modify-write-row.js * Update read-row.js * Update sampleRowKeys.ts
1 parent 4bb14d6 commit 2fdf98f

File tree

4 files changed

+85
-27
lines changed

4 files changed

+85
-27
lines changed

src/tabular-api-surface.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,23 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
902902
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
903903
const gaxOptions =
904904
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
905+
906+
/*
907+
The following line of code sets the timeout if it was provided while
908+
creating the client. This will be used to determine if the client should
909+
retry on DEADLINE_EXCEEDED errors. Eventually, this will be handled
910+
downstream in google-gax.
911+
*/
912+
const timeout = gaxOptions?.timeout;
913+
const callTimeMillis = new Date().getTime();
914+
905915
this.sampleRowKeysStream(gaxOptions)
906-
.on('error', callback)
916+
.on('error', (error: grpc.ServiceError) => {
917+
if (timeout && timeout > new Date().getTime() - callTimeMillis) {
918+
error.code = grpc.status.DEADLINE_EXCEEDED;
919+
}
920+
callback(error);
921+
})
907922
.pipe(
908923
concat((keys: string[]) => {
909924
callback(null, keys);

testproxy/known_failures.txt

-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ TestReadRows_Retry_WithRoutingCookie\|
1111
TestReadRows_Retry_WithRoutingCookie_MultipleErrorResponses\|
1212
TestReadRows_Retry_WithRetryInfo\|
1313
TestReadRows_Retry_WithRetryInfo_MultipleErrorResponse\|
14-
TestSampleRowKeys_Generic_DeadlineExceeded\|
1514
TestSampleRowKeys_Retry_WithRoutingCookie\|
1615
TestSampleRowKeys_Generic_CloseClient

testproxy/services/sample-row-keys.js

+21-25
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,34 @@
1414
'use strict';
1515

1616
const grpc = require('@grpc/grpc-js');
17-
17+
const {
18+
getSRKRequest,
19+
} = require('../../build/testproxy/services/utils/request/sampleRowKeys.js');
1820
const normalizeCallback = require('./utils/normalize-callback.js');
1921

20-
const v2 = Symbol.for('v2');
21-
2222
const sampleRowKeys = ({clientMap}) =>
2323
normalizeCallback(async rawRequest => {
2424
const {request} = rawRequest;
25-
const {request: sampleRowKeysRequest} = request;
26-
const {tableName} = sampleRowKeysRequest;
27-
const {clientId} = request;
25+
const {clientId, request: sampleRowKeysRequest} = request;
26+
const {appProfileId, tableName} = sampleRowKeysRequest;
27+
28+
const bigtable = clientMap.get(clientId);
29+
bigtable.appProfileId = appProfileId;
30+
31+
try {
32+
const response = await getSRKRequest(bigtable, {appProfileId, tableName});
2833

29-
const appProfileId = clientMap.get(clientId).appProfileId;
30-
const client = clientMap.get(clientId)[v2];
31-
const samples = await new Promise((res, rej) => {
32-
const response = [];
33-
client
34-
.sampleRowKeys({
35-
appProfileId,
36-
tableName,
37-
})
38-
.on('data', data => {
39-
response.push(data);
40-
})
41-
.on('error', rej)
42-
.on('end', () => res(response));
43-
});
34+
return {
35+
status: {code: grpc.status.OK, details: []},
36+
response,
37+
};
38+
} catch (error) {
39+
console.error('Error:', error.code);
4440

45-
return {
46-
status: {code: grpc.status.OK, details: []},
47-
samples,
48-
};
41+
return {
42+
status: {code: error.code, details: []},
43+
};
44+
}
4945
});
5046

5147
module.exports = sampleRowKeys;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import * as protos from '../../../../protos/protos';
16+
17+
type SRKRequest = protos.google.bigtable.v2.ISampleRowKeysRequest;
18+
type SRKResponse = protos.google.bigtable.v2.ISampleRowKeysResponse;
19+
20+
/**
21+
* This function will create a request that can be passed into the
22+
* handwritten ßsampleRowKeys method and calls the Gapic layer under the hood.
23+
*
24+
* @param {any} client Bigtable client
25+
* @param {SRKRequest} request The sampleRowKeys request information
26+
* that can be sent to the Gapic layer.
27+
* @returns {Promise<SRKResponse>} A reponse that can be passed into the
28+
* sampleRowKeys Gapic layer.
29+
*/
30+
export function getSRKRequest(
31+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
32+
client: any,
33+
request: SRKRequest
34+
): Promise<SRKResponse> {
35+
const {tableName} = request;
36+
37+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
38+
const getTableInfo = (bigtable: any, tableName: any) => {
39+
const [, , , instanceId, , tableId] = tableName.split('/');
40+
const instance = bigtable.instance(instanceId);
41+
return instance.table(tableId);
42+
};
43+
44+
const table = getTableInfo(client, tableName);
45+
const sampleRowKeysResponse = table.sampleRowKeys();
46+
47+
return sampleRowKeysResponse;
48+
}

0 commit comments

Comments
 (0)