Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alkatrivedi committed Dec 26, 2024
1 parent e65f9d6 commit fa315de
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/session-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class SessionFactory
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'true'
? this.multiplexedSession_
: this.pool_;
sessionHandler?.getSession((err, session) => callback(err, session));
sessionHandler!.getSession((err, session) => callback(err, session));
}

/**
Expand Down
20 changes: 20 additions & 0 deletions test/spanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import protobuf = google.spanner.v1;
import Priority = google.spanner.v1.RequestOptions.Priority;
import TypeCode = google.spanner.v1.TypeCode;
import NullValue = google.protobuf.NullValue;
import {SessionFactory} from '../src/session-factory';

const {
AlwaysOnSampler,
Expand Down Expand Up @@ -5075,6 +5076,25 @@ describe('Spanner with mock server', () => {
done();
});
});

describe('session-factory', () => {
after(() => {
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS = 'false';
});
it('should execute table mutations without leaking sessions', () => {
const database = newTestDatabase();
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS = 'true';
const sessionFactory = database.sessionFactory_ as SessionFactory;
try {
sessionFactory.getSession(() => {});
} catch (e) {
assert.strictEqual(
(e as Error).message,
"Cannot read properties of undefined (reading 'getSession')"
);
}
});
});
});

function executeSimpleUpdate(
Expand Down

0 comments on commit fa315de

Please sign in to comment.