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 9fde1d2 commit 505974a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,10 @@ class Instance extends common.GrpcServiceObject {
if (!this.databases_.has(key!)) {
const db = new Database(this, name, poolOptions, queryOptions);
db._observabilityOptions = this._observabilityOptions;
db._clientId = (this.parent as Spanner)._nthClientId;
const parent = this.parent as Spanner;
if (parent && parent._nthClientId) {
db._clientId = parent._nthClientId;
}
this.databases_.set(key!, db);
}
return this.databases_.get(key!)!;
Expand Down
8 changes: 8 additions & 0 deletions src/request_id_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ function _metadataWithRequestId(
return withReqId;
}

function nextNthRequest(database): number {
if (!(database && typeof database._nextNthRequest === 'function')) {
return 1;
}
return database._nextNthRequest();
}

export {
AtomicCounter,
X_GOOG_SPANNER_REQUEST_ID_HEADER,
Expand All @@ -311,6 +318,7 @@ export {
extractRequestID,
injectRequestIDIntoError,
injectRequestIDIntoHeaders,
nextNthRequest,
nextSpannerClientId,
newAtomicCounter,
};
19 changes: 11 additions & 8 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
import {grpc, CallOptions} from 'google-gax';
import IRequestOptions = google.spanner.v1.IRequestOptions;
import {Spanner} from '.';
import {injectRequestIDIntoHeaders, nextNthRequest} from './request_id_header';
export type GetSessionResponse = [Session, r.Response];

/**
Expand Down Expand Up @@ -323,10 +324,11 @@ export class Session extends common.GrpcServiceObject {
method: 'deleteSession',
reqOpts,
gaxOpts,
headers: database._metadataWithRequestId(
database._nextNthRequest(),
1,
this.commonHeaders_
headers: injectRequestIDIntoHeaders(
this.commonHeaders_,
this.session,
nextNthRequest(database),
1
),
},
callback!
Expand Down Expand Up @@ -400,10 +402,11 @@ export class Session extends common.GrpcServiceObject {
method: 'getSession',
reqOpts,
gaxOpts,
headers: database._metadataWithRequestId(
database._nextNthRequest(),
1,
headers
headers: injectRequestIDIntoHeaders(
headers,
this.session,
nextNthRequest(database),
1
),
},
(err, resp) => {
Expand Down
9 changes: 1 addition & 8 deletions src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
setSpanError,
setSpanErrorAndException,
} from './instrument';
import {injectRequestIDIntoHeaders} from './request_id_header';
import {injectRequestIDIntoHeaders, nextNthRequest} from './request_id_header';

export type Rows = Array<Row | Json>;
const RETRY_INFO_TYPE = 'type.googleapis.com/google.rpc.retryinfo';
Expand Down Expand Up @@ -3063,13 +3063,6 @@ function isErrorAborted(err): boolean {
);
}

function nextNthRequest(database): number {
if (!(database && typeof database._nextNthRequest === 'function')) {
return 1;
}
return database._nextNthRequest();
}

/*! Developer Documentation
*
* All async methods (except for streams) return a Promise in the event
Expand Down

0 comments on commit 505974a

Please sign in to comment.