Skip to content

Commit

Permalink
fix: do not create sessions after getDatabases call (#1228)
Browse files Browse the repository at this point in the history
* fix: do not create sessions after getDatabases call

* test: check all returned databases

* test: add check for min:0 to instance test

Co-authored-by: Alex <[email protected]>
Co-authored-by: skuruppu <[email protected]>
Co-authored-by: Stephen <[email protected]>
  • Loading branch information
4 people authored Oct 2, 2020
1 parent 63b03cd commit 53d5f37
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ class Instance extends common.GrpcServiceObject {
let databases: Database[] | null = null;
if (rowDatabases) {
databases = rowDatabases.map(database => {
const databaseInstance = self.database(database.name!);
const databaseInstance = self.database(database.name!, {min: 0});
databaseInstance.metadata = database;
return databaseInstance;
});
Expand Down
3 changes: 2 additions & 1 deletion test/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,9 @@ describe('Instance', () => {
it('should create and return Database objects', done => {
const fakeDatabaseInstance = {};

instance.database = name => {
instance.database = (name, options) => {
assert.strictEqual(name, DATABASES[0].name);
assert.strictEqual((options as SessionPoolOptions).min, 0);
return fakeDatabaseInstance as Database;
};

Expand Down
5 changes: 5 additions & 0 deletions test/spanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,11 @@ describe('Spanner with mock server', () => {
it('should list databases', async () => {
const [databases] = await instance.getDatabases();
assert.strictEqual(databases.length, 2);
// Assert that listing the databases does not cause a session pool to be
// initialized for the databases.
for (const db of databases) {
assert.strictEqual((db.pool_ as SessionPool).size, 0);
}
});

it('should create a database', async () => {
Expand Down

0 comments on commit 53d5f37

Please sign in to comment.