@@ -369,6 +369,51 @@ describe('BigQuery', () => {
369369 assert . strictEqual ( res . totalRows , '100' ) ;
370370 } ) ;
371371
372+ describe ( 'Query timeout' , ( ) => {
373+ let longRunningQuery = '' ;
374+
375+ beforeEach ( ( ) => {
376+ const tableId = generateName ( 'table' ) ;
377+ longRunningQuery = `CREATE TABLE ${ dataset . projectId } .${ dataset . id } .${ tableId } AS SELECT num FROM UNNEST(GENERATE_ARRAY(1,1000000)) as num` ;
378+ } ) ;
379+
380+ it ( 'should throw a timeout error with jobs.query' , async ( ) => {
381+ const qOpts : QueryOptions = {
382+ timeoutMs : 1000 ,
383+ } ;
384+ let foundError : Error | null = null ;
385+ try {
386+ await bigquery . query ( longRunningQuery , qOpts ) ;
387+ } catch ( error : unknown ) {
388+ foundError = error as Error ;
389+ }
390+ assert . notEqual ( foundError , null ) ;
391+ assert . equal (
392+ foundError ?. message ,
393+ 'The query did not complete before 1000ms'
394+ ) ;
395+ } ) ;
396+
397+ it ( 'should throw a timeout error without jobs.query' , async ( ) => {
398+ const jobId = generateName ( 'job' ) ;
399+ const qOpts : QueryOptions = {
400+ job : bigquery . job ( jobId ) ,
401+ timeoutMs : 1000 ,
402+ } ;
403+ let foundError : Error | null = null ;
404+ try {
405+ await bigquery . query ( longRunningQuery , qOpts ) ;
406+ } catch ( error : unknown ) {
407+ foundError = error as Error ;
408+ }
409+ assert . notEqual ( foundError , null ) ;
410+ assert . equal (
411+ foundError ?. message ,
412+ 'The query did not complete before 1000ms'
413+ ) ;
414+ } ) ;
415+ } ) ;
416+
372417 it ( 'should allow querying in series' , done => {
373418 bigquery . query (
374419 query ,
0 commit comments