Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed Dec 24, 2024
1 parent 505974a commit 12efa68
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 32 deletions.
2 changes: 0 additions & 2 deletions src/batch-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ class BatchTransaction extends Snapshot {
'BatchTransaction.createQueryPartitions',
traceConfig,
span => {
const database = this.session.parent as Database;
const headers: {[k: string]: string} = {};
if (this._getSpanner().routeToLeaderEnabled) {
addLeaderAwareRoutingHeader(headers);
Expand Down Expand Up @@ -289,7 +288,6 @@ class BatchTransaction extends Snapshot {
if (this._getSpanner().routeToLeaderEnabled) {
addLeaderAwareRoutingHeader(headers);
}
const database = this.session.parent as Database;
this.createPartitions_(
{
client: 'SpannerClient',
Expand Down
5 changes: 2 additions & 3 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ import {
LongRunningCallback,
NormalCallback,
PagedOptionsWithFilter,
CLOUD_RESOURCE_HEADER,
PagedResponse,
RequestCallback,
ResourceCallback,
Expand Down Expand Up @@ -764,7 +763,7 @@ class Database extends common.GrpcServiceObject {
...priorMetadata,
};
withReqId[X_GOOG_SPANNER_REQUEST_ID_HEADER] = craftRequestId(
this._clientId,
this._clientId || 1,
1, // TODO: Properly infer the channelId
nthRequest,
attempt
Expand Down Expand Up @@ -1040,7 +1039,7 @@ class Database extends common.GrpcServiceObject {
const headers = this._metadataWithRequestId(
this._nextNthRequest(),
1,
this.commonHeaders_,
this.commonHeaders_
);
if (this._getSpanner().routeToLeaderEnabled) {
addLeaderAwareRoutingHeader(headers);
Expand Down
22 changes: 7 additions & 15 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ export class Session extends common.GrpcServiceObject {
reqOpts,
gaxOpts,
headers: injectRequestIDIntoHeaders(
this.commonHeaders_,
this.session,
this.resourceHeader_,
this,
nextNthRequest(database),
1
),
Expand Down Expand Up @@ -461,25 +461,17 @@ export class Session extends common.GrpcServiceObject {
method: 'executeSql',
reqOpts,
gaxOpts,
headers: database._metadataWithRequestId(
database._nextNthRequest(),
1,
this.commonHeaders_
headers: injectRequestIDIntoHeaders(
this.commonHeaders_,
this,
nextNthRequest(database),
1
),
},
callback!
);
}

public _metadataWithRequestId(
nthRequest: number,
attempt: number,
priorMetadata?: {[k: string]: string}
): {[k: string]: string} {
const database = this.parent as Database;
return database._metadataWithRequestId(nthRequest, attempt, priorMetadata);
}

/**
* Create a PartitionedDml transaction.
*
Expand Down
1 change: 0 additions & 1 deletion src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ export class Snapshot extends EventEmitter {
opts: this._observabilityOptions,
dbName: this._dbName!,
};
const database = this.session.parent as Database;
return startTrace('Snapshot.begin', traceConfig, span => {
span.addEvent('Begin Transaction');

Expand Down
2 changes: 1 addition & 1 deletion test/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2111,7 +2111,7 @@ describe('Database', () => {
config.headers,
Object.assign(
{
[LEADER_AWARE_ROUTING_HEADER]: true,
[LEADER_AWARE_ROUTING_HEADER]: 'true',
[X_GOOG_SPANNER_REQUEST_ID_HEADER]: craftRequestId(1, 1, 1, 1),
},
database.commonHeaders_
Expand Down
6 changes: 3 additions & 3 deletions test/gapic_spanner_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,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'];
// console.log('headers', actualHeaders);
// assert.deepStrictEqual(actualRequestID, 'foo');
});

it('invokes batchCreateSessions without error using callback', async () => {
Expand Down
9 changes: 5 additions & 4 deletions test/request_id_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

/* eslint-disable prefer-rest-params */
import * as assert from 'assert';
import {AtomicCounter} from '../src/request_id_header';

describe('AtomicCounter', () => {
Expand All @@ -35,13 +36,13 @@ describe('AtomicCounter', () => {
const ac1 = new AtomicCounter(1);
assert.strictEqual(ac1.value(), 1);
assert.strictEqual(
ac0.increment(1 << 32),
(1 << 32) + 1,
ac1.increment(1 << 27),
(1 << 27) + 1,
'increment should return the added value'
);
assert.strictEqual(
ac0.value(),
(1 << 32) + 1,
ac1.value(),
(1 << 27) + 1,
'increment should have modified the value'
);
done();
Expand Down
14 changes: 12 additions & 2 deletions test/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import {
LEADER_AWARE_ROUTING_HEADER,
} from '../src/common';
import {Database, Instance, Spanner} from '../src';
import {
X_GOOG_SPANNER_REQUEST_ID_HEADER,
craftRequestId,
} from '../src/request_id_header';

let promisified = false;
const fakePfy = extend({}, pfy, {
Expand Down Expand Up @@ -262,7 +266,10 @@ describe('Session', () => {
name: session.formattedName_,
});
assert.deepStrictEqual(config.gaxOpts, {});
assert.deepStrictEqual(config.headers, session.commonHeaders_);
assert.deepStrictEqual(config.headers, {
...session.commonHeaders_,
[X_GOOG_SPANNER_REQUEST_ID_HEADER]: craftRequestId(1, 1, 1, 1),
});

assert.strictEqual(callback_, callback);
return requestReturnValue;
Expand Down Expand Up @@ -403,7 +410,10 @@ describe('Session', () => {
sql: 'SELECT 1',
});
assert.deepStrictEqual(config.gaxOpts, {});
assert.deepStrictEqual(config.headers, session.commonHeaders_);
assert.deepStrictEqual(config.headers, {
...session.commonHeaders_,
[X_GOOG_SPANNER_REQUEST_ID_HEADER]: craftRequestId(1, 1, 1, 1),
});
assert.strictEqual(callback_, callback);
return requestReturnValue;
};
Expand Down
2 changes: 1 addition & 1 deletion test/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ describe('Transaction', () => {
Object.assign(
{
[X_GOOG_SPANNER_REQUEST_ID_HEADER]: craftRequestId(1, 1, 1, 1),
[LEADER_AWARE_ROUTING_HEADER]: true,
[LEADER_AWARE_ROUTING_HEADER]: 'true',
},
transaction.commonHeaders_
)
Expand Down

0 comments on commit 12efa68

Please sign in to comment.