Skip to content

Commit

Permalink
refactor: test for session-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
alkatrivedi committed Dec 27, 2024
1 parent 239ddb1 commit 025dd00
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions test/session-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {FakeTransaction} from './session-pool';
import {ReleaseError} from '../src/session-pool';

describe('SessionFactory', () => {
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS = 'true';
let sessionFactory;
let fakeSession;
let fakeMuxSession;
Expand Down Expand Up @@ -78,35 +77,37 @@ describe('SessionFactory', () => {
});

describe('instantiation', () => {
before(() => {
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS = 'false';
});
describe('when GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is disabled', () => {
before(() => {
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS = 'false';
});

it('should create a SessionPool object', () => {
assert(sessionFactory.pool_ instanceof SessionPool);
});
it('should create a SessionPool object', () => {
assert(sessionFactory.pool_ instanceof SessionPool);
});

it('should accept a custom Pool class', () => {
function FakePool() {}
FakePool.prototype.on = util.noop;
FakePool.prototype.open = util.noop;

const sessionFactory = new SessionFactory(
DATABASE,
NAME,
FakePool as {} as db.SessionPoolConstructor
);
assert(sessionFactory.pool_ instanceof FakePool);
});
it('should accept a custom Pool class', () => {
function FakePool() {}
FakePool.prototype.on = util.noop;
FakePool.prototype.open = util.noop;

it('should open the pool', () => {
const openStub = sandbox
.stub(SessionPool.prototype, 'open')
.callsFake(() => {});
const sessionFactory = new SessionFactory(
DATABASE,
NAME,
FakePool as {} as db.SessionPoolConstructor
);
assert(sessionFactory.pool_ instanceof FakePool);
});

new SessionFactory(DATABASE, NAME, POOL_OPTIONS);
it('should open the pool', () => {
const openStub = sandbox
.stub(SessionPool.prototype, 'open')
.callsFake(() => {});

assert.strictEqual(openStub.callCount, 1);
new SessionFactory(DATABASE, NAME, POOL_OPTIONS);

assert.strictEqual(openStub.callCount, 1);
});
});

describe('when GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is enabled', () => {
Expand All @@ -120,7 +121,7 @@ describe('SessionFactory', () => {
);
});

it('should initiate the multiplexed session creation if GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS is enabled', () => {
it('should initiate the multiplexed session creation', () => {
const createSessionStub = sandbox
.stub(MultiplexedSession.prototype, 'createSession')
.callsFake(() => {});
Expand Down

0 comments on commit 025dd00

Please sign in to comment.