@@ -27,7 +27,7 @@ import {Family} from '../src/family.js';
2727import { Mutation } from '../src/mutation.js' ;
2828import { Row } from '../src/row.js' ;
2929import * as tblTypes from '../src/table' ;
30- import { Bigtable } from '../src' ;
30+ import { Bigtable , RequestOptions } from '../src' ;
3131import { EventEmitter } from 'events' ;
3232
3333const sandbox = sinon . createSandbox ( ) ;
@@ -544,7 +544,9 @@ describe('Bigtable/Table', () => {
544544 assert . strictEqual ( config . method , 'readRows' ) ;
545545 assert . strictEqual ( config . reqOpts . tableName , TABLE_NAME ) ;
546546 assert . strictEqual ( config . reqOpts . appProfileId , undefined ) ;
547- assert . strictEqual ( config . gaxOpts , undefined ) ;
547+ assert . deepStrictEqual ( config . gaxOpts , {
548+ otherArgs : { headers : { 'bigtable-attempt' : 0 } } ,
549+ } ) ;
548550 done ( ) ;
549551 } ;
550552 table . createReadStream ( ) ;
@@ -2570,6 +2572,7 @@ describe('Bigtable/Table', () => {
25702572 let fakeStatuses : any ;
25712573 // eslint-disable-next-line @typescript-eslint/no-explicit-any
25722574 let entryRequests : any ;
2575+ const requestArgs : RequestOptions [ ] = [ ] ;
25732576
25742577 beforeEach ( ( ) => {
25752578 entryRequests = [ ] ;
@@ -2599,6 +2602,7 @@ describe('Bigtable/Table', () => {
25992602 ] ;
26002603 // eslint-disable-next-line @typescript-eslint/no-explicit-any
26012604 table . bigtable . request = ( config : any ) => {
2605+ requestArgs . push ( JSON . parse ( JSON . stringify ( config ) ) ) ;
26022606 entryRequests . push ( config . reqOpts . entries ) ;
26032607 const stream = new PassThrough ( {
26042608 objectMode : true ,
@@ -2612,6 +2616,25 @@ describe('Bigtable/Table', () => {
26122616 } ;
26132617 } ) ;
26142618
2619+ it ( 'should send attempt header' , done => {
2620+ table . mutate ( entries , ( ) => {
2621+ assert . strictEqual ( requestArgs . length , 2 ) ;
2622+ assert . strictEqual (
2623+ ( requestArgs [ 0 ] . gaxOpts as any ) [ 'otherArgs' ] [ 'headers' ] [
2624+ 'bigtable-attempt'
2625+ ] ,
2626+ 0
2627+ ) ;
2628+ assert . strictEqual (
2629+ ( requestArgs [ 1 ] . gaxOpts as any ) [ 'otherArgs' ] [ 'headers' ] [
2630+ 'bigtable-attempt'
2631+ ] ,
2632+ 1
2633+ ) ;
2634+ done ( ) ;
2635+ } ) ;
2636+ } ) ;
2637+
26152638 it ( 'should succeed after a retry' , done => {
26162639 table . maxRetries = 1 ;
26172640 table . mutate ( entries , done ) ;
@@ -2630,17 +2653,20 @@ describe('Bigtable/Table', () => {
26302653
26312654 describe ( 'rpc level retries' , ( ) => {
26322655 let emitters : EventEmitter [ ] | null ; // = [((stream: Writable) => { stream.push([{ key: 'a' }]);
2656+ let requestArgs : RequestOptions [ ] = [ ] ;
26332657
26342658 // eslint-disable-next-line @typescript-eslint/no-explicit-any
26352659 let entryRequests : any ;
26362660
26372661 beforeEach ( ( ) => {
26382662 emitters = null ; // This needs to be assigned in each test case.
26392663
2664+ requestArgs = [ ] ;
26402665 entryRequests = [ ] ;
26412666
26422667 // eslint-disable-next-line @typescript-eslint/no-explicit-any
26432668 table . bigtable . request = ( config : any ) => {
2669+ requestArgs . push ( JSON . parse ( JSON . stringify ( config ) ) ) ;
26442670 entryRequests . push ( config . reqOpts . entries ) ;
26452671 const stream = new PassThrough ( {
26462672 objectMode : true ,
@@ -2707,6 +2733,36 @@ describe('Bigtable/Table', () => {
27072733 done ( ) ;
27082734 } ) ;
27092735 } ) ;
2736+
2737+ it ( 'should send attempt header' , done => {
2738+ const error = new Error ( 'retryable' ) as ServiceError ;
2739+ error . code = 14 ; // Unavailable
2740+ emitters = [
2741+ ( ( stream : Writable ) => {
2742+ stream . emit ( 'error' , error ) ;
2743+ } ) as { } as EventEmitter ,
2744+ ( ( stream : Writable ) => {
2745+ stream . end ( ) ;
2746+ } ) as { } as EventEmitter ,
2747+ ] ;
2748+ table . maxRetries = 1 ;
2749+ table . mutate ( entries , ( ) => {
2750+ assert . strictEqual ( requestArgs . length , 2 ) ;
2751+ assert . strictEqual (
2752+ ( requestArgs [ 0 ] . gaxOpts as any ) [ 'otherArgs' ] [ 'headers' ] [
2753+ 'bigtable-attempt'
2754+ ] ,
2755+ 0
2756+ ) ;
2757+ assert . strictEqual (
2758+ ( requestArgs [ 1 ] . gaxOpts as any ) [ 'otherArgs' ] [ 'headers' ] [
2759+ 'bigtable-attempt'
2760+ ] ,
2761+ 1
2762+ ) ;
2763+ done ( ) ;
2764+ } ) ;
2765+ } ) ;
27102766 } ) ;
27112767 } ) ;
27122768
0 commit comments