File tree Expand file tree Collapse file tree 2 files changed +25
-9
lines changed
packages/cubejs-postgres-driver Expand file tree Collapse file tree 2 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,8 @@ export class PostgresDriver<Config extends PostgresDriverConfiguration = Postgre
6666 return 2 ;
6767 }
6868
69+ private enabled : boolean = false ;
70+
6971 protected readonly pool : Pool ;
7072
7173 protected readonly config : Partial < Config > ;
@@ -107,13 +109,15 @@ export class PostgresDriver<Config extends PostgresDriverConfiguration = Postgre
107109 executionTimeout : getEnv ( 'dbQueryTimeout' , { dataSource } ) ,
108110 ...config ,
109111 } ;
112+ this . enabled = true ;
110113 }
111114
112115 /**
113116 * The easiest way how to add additional configuration from env variables, because
114117 * you cannot call method in RedshiftDriver.constructor before super.
115118 */
116119 protected getInitialConfiguration (
120+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
117121 dataSource : string ,
118122 ) : Partial < PostgresDriverConfiguration > {
119123 return {
@@ -334,8 +338,11 @@ export class PostgresDriver<Config extends PostgresDriverConfiguration = Postgre
334338 }
335339 }
336340
337- public release ( ) {
338- return this . pool . end ( ) ;
341+ public async release ( ) {
342+ if ( this . enabled ) {
343+ this . pool . end ( ) ;
344+ this . enabled = false ;
345+ }
339346 }
340347
341348 public param ( paramIndex : number ) {
Original file line number Diff line number Diff line change 11import { PostgresDBRunner } from '@cubejs-backend/testing-shared' ;
2-
32import { StartedTestContainer } from 'testcontainers' ;
4-
53import { PostgresDriver } from '../src' ;
64
75const streamToArray = require ( 'stream-to-array' ) ;
@@ -25,11 +23,7 @@ describe('PostgresDriver', () => {
2523 } ) ;
2624
2725 afterAll ( async ( ) => {
28- await driver . release ( ) ;
29-
30- if ( container ) {
31- await container . stop ( ) ;
32- }
26+ await container . stop ( ) ;
3327 } ) ;
3428
3529 test ( 'type coercion' , async ( ) => {
@@ -121,4 +115,19 @@ describe('PostgresDriver', () => {
121115 ) ;
122116 }
123117 } ) ;
118+
119+ // Note: This test MUST be the last in the list.
120+ test ( 'release' , async ( ) => {
121+ expect ( async ( ) => {
122+ await driver . release ( ) ;
123+ } ) . not . toThrowError (
124+ / C a l l e d e n d o n p o o l m o r e t h a n o n c e /
125+ ) ;
126+
127+ expect ( async ( ) => {
128+ await driver . release ( ) ;
129+ } ) . not . toThrowError (
130+ / C a l l e d e n d o n p o o l m o r e t h a n o n c e /
131+ ) ;
132+ } ) ;
124133} ) ;
You can’t perform that action at this time.
0 commit comments