Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/cubejs-firebolt-driver/src/FireboltDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export class FireboltDriver extends BaseDriver implements DriverInterface {
testConnectionTimeout?: number,
} = {},
) {
super(config);
// Set connection timeout to 2 minutes to allow the engine to start if it's stopped
super({ testConnectionTimeout: 120000, ...config });

const dataSource =
config.dataSource ||
Expand Down Expand Up @@ -122,6 +123,7 @@ export class FireboltDriver extends BaseDriver implements DriverInterface {
private async initConnection() {
try {
const connection = await this.firebolt.connect(this.config.connection);
await this.ensureEngineRunning();
return connection;
} catch (e) {
this.connection = null;
Expand Down Expand Up @@ -174,7 +176,7 @@ export class FireboltDriver extends BaseDriver implements DriverInterface {
await connection.testConnection();
} catch (error) {
console.log(error);
throw new Error('Unable to connect');
throw error;
}
}

Expand Down
33 changes: 33 additions & 0 deletions packages/cubejs-firebolt-driver/test/autostart.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {assertDataSource, getEnv} from '@cubejs-backend/shared';
import { DriverTests } from '@cubejs-backend/testing-shared';

import { FireboltDriver } from '../src';
import { Firebolt } from 'firebolt-sdk';
import { version } from 'firebolt-sdk/package.json';

describe('FireboltDriver autostart', () => {
let tests: DriverTests;
Expand Down Expand Up @@ -30,4 +33,34 @@ describe('FireboltDriver autostart', () => {
expect(driver.ensureEngineRunning).toHaveBeenCalled();
}
});
test('starts the engine after connection', async () => {
const dataSource = assertDataSource('default');

const username = getEnv('dbUser', { dataSource });
const auth = username.includes('@')
? { username, password: getEnv('dbPass', { dataSource }) }
: { client_id: username, client_secret: getEnv('dbPass', { dataSource }) };
const engineName = getEnv('fireboltEngineName', { dataSource });
const firebolt = Firebolt({
apiEndpoint: getEnv('fireboltApiEndpoint', { dataSource }) || 'api.app.firebolt.io',
})
await firebolt.connect({
auth,
database: getEnv('dbName', { dataSource }),
account: getEnv('fireboltAccount', { dataSource }),
engineEndpoint: getEnv('fireboltEngineEndpoint', { dataSource }),
additionalParameters: {
userClients: [{
name: 'CubeDev+Cube',
version
}]
},
});

const engine = await firebolt.resourceManager.engine.getByName(engineName);
await engine.stop();

driver = new FireboltDriver({});
await driver.testConnection();
});
});
Loading