Skip to content

Commit

Permalink
All: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed Feb 11, 2025
1 parent e683e25 commit ebab047
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/request_id_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ function newAtomicCounter(n?: number): AtomicCounter {
return new AtomicCounter(n);
}

const X_GOOG_REQ_ID_REGEX = /(\d+\.){5}\d+/;

interface withHeaders {
headers: {[k: string]: string};
}
Expand Down Expand Up @@ -189,8 +187,11 @@ export interface RequestIDError extends grpc.ServiceError {
requestID: string;
}

const X_GOOG_REQ_ID_REGEX = /^1\.[0-9A-Fa-f]{8}(\.\d+){3}\.\d+/;

export {
AtomicCounter,
X_GOOG_REQ_ID_REGEX,
X_GOOG_SPANNER_REQUEST_ID_HEADER,
craftRequestId,
injectRequestIDIntoError,
Expand Down
10 changes: 7 additions & 3 deletions test/gapic_spanner_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import * as spannerModule from '../src';
import {PassThrough} from 'stream';

import {protobuf} from 'google-gax';
import {
X_GOOG_REQ_ID_REGEX,
X_GOOG_SPANNER_REQUEST_ID_HEADER,
} from '../src/request_id_header';

// Dynamically loaded proto JSON is needed to get the type information
// to fill in default values for request objects
Expand Down Expand Up @@ -486,9 +490,9 @@ describe('v1.SpannerClient', () => {
).getCall(0).args[1].otherArgs.headers;
const actualHeaderRequestParams = actualHeaders['x-goog-request-params'];
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
// const actualRequestID = actualHeaders['x-goog-spanner-request-id'];
// console.log('headers', actualHeaders);
// assert.deepStrictEqual(actualRequestID, 'foo');
// const actualRequestID = actualHeaders[X_GOOG_SPANNER_REQUEST_ID_HEADER];
// console.log(`headers ${JSON.stringify(actualHeaders)}`);
// assert.deepStrictEqual(actualRequestID!.match(X_GOOG_REQ_ID_REGEX) !== null, true);
});

it('invokes batchCreateSessions without error using callback', async () => {
Expand Down
13 changes: 4 additions & 9 deletions test/spanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import {
} from '../src/common';
import {
RequestIDError,
X_GOOG_REQ_ID_REGEX,
X_GOOG_SPANNER_REQUEST_ID_HEADER,
randIdForProcess,
resetNthClientId,
} from '../src/request_id_header';
Expand All @@ -74,7 +76,6 @@ import Priority = google.spanner.v1.RequestOptions.Priority;
import TypeCode = google.spanner.v1.TypeCode;
import NullValue = google.protobuf.NullValue;
import {SessionFactory} from '../src/session-factory';
import {X_GOOG_SPANNER_REQUEST_ID_HEADER} from '../src/request_id_header';

const {
AlwaysOnSampler,
Expand Down Expand Up @@ -313,7 +314,6 @@ describe('Spanner with mock server', () => {
servicePath: 'localhost',
port,
sslCreds: grpc.credentials.createInsecure(),
// interceptors: [xGoogReqIDInterceptor.generateLoggingClientInterceptor()],
});
// Gets a reference to a Cloud Spanner instance and database
instance = spanner.instance('instance');
Expand Down Expand Up @@ -2748,7 +2748,7 @@ describe('Spanner with mock server', () => {
`${grpc.status.NOT_FOUND} NOT_FOUND: ${fooNotFoundErr.message}`
);
assert.deepStrictEqual(
(e as RequestIDError).requestID.match(requestIDRegex) != null,
(e as RequestIDError).requestID.match(requestIDRegex) !== null,
true
);
}
Expand Down Expand Up @@ -2796,7 +2796,7 @@ describe('Spanner with mock server', () => {
`${grpc.status.NOT_FOUND} NOT_FOUND: ${fooNotFoundErr.message}`
);
assert.deepStrictEqual(
(e as RequestIDError).requestID.match(requestIDRegex) != null,
(e as RequestIDError).requestID.match(requestIDRegex) !== null,
true
);
}
Expand Down Expand Up @@ -2877,7 +2877,6 @@ describe('Spanner with mock server', () => {
(e as ServiceError).message,
'No resources available.'
);
// assert.deepStrictEqual((e as RequestIDError).requestID,`1.${randIdForProcess}.1.1.1.1`);
}
} finally {
if (tx1) {
Expand Down Expand Up @@ -2952,7 +2951,6 @@ describe('Spanner with mock server', () => {
assert.fail('missing expected error');
} catch (err) {
assert.strictEqual((err as ServiceError).code, Status.NOT_FOUND);
// assert.deepStrictEqual((err as RequestIDError).requestID,`1.${randIdForProcess}.1.1.1.1`);
} finally {
await database.close();
}
Expand Down Expand Up @@ -3014,7 +3012,6 @@ describe('Spanner with mock server', () => {
(err as ServiceError).code,
Status.PERMISSION_DENIED
);
// assert.deepStrictEqual((err as RequestIDError).requestID,`1.${randIdForProcess}.1.1.1.1`);
} finally {
await database.close();
}
Expand Down Expand Up @@ -5440,5 +5437,3 @@ function getRowCountFromStreamingSql(
function sleep(ms): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}

const X_GOOG_REQ_ID_REGEX = /^1\.[0-9A-Fa-f]{8}(\.\d+){3}\.\d+/;

0 comments on commit ebab047

Please sign in to comment.