Skip to content

Commit

Permalink
Move pool cluster promise test to builtin-runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael03 committed Jul 10, 2023
1 parent 142cb6a commit 588b875
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { describe, it, before, after } from 'node:test';
import assert from 'node:assert';
import common from '../../../common.js';
import { createPoolCluster } from "../../../../promise.js"

describe('Test pool cluster', { timeout: 1000 }, () => {

it('should propagate warn event to promise wrapper', (t, done) => {

const poolCluster = createPoolCluster();
/* eslint-disable no-invalid-this */
poolCluster
.once('warn', function () {
assert.equal(this, poolCluster);
done();
})
/* eslint-enable no-invalid-this */
poolCluster.poolCluster.emit('warn', new Error());
});

it('should propagate remove event to promise wrapper', (t, done) => {

const poolCluster = createPoolCluster();
/* eslint-disable no-invalid-this */
poolCluster
.once('remove', function () {
assert.equal(this, poolCluster);
done();
});
/* eslint-enable no-invalid-this */
poolCluster.poolCluster.emit('remove');
});
});
24 changes: 0 additions & 24 deletions test/integration/promise-wrappers/test-promise-wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const assert = require('assert');

const createConnection = require('../../../promise.js').createConnection;
const createPool = require('../../../promise.js').createPool;
const createPoolCluster = require('../../../promise.js').createPoolCluster;

// it's lazy exported from main index.js as well. Test that it's same function
const mainExport = require('../../../index.js').createConnectionPromise;
Expand All @@ -20,7 +19,6 @@ assert.equal(mainExport, createConnection);
let doneCalled = false;
let exceptionCaught = false;
let doneEventsConnect = false;
let eventsPoolCluster = false;

let doneCalledPool = false;
let exceptionCaughtPool = false;
Expand Down Expand Up @@ -207,26 +205,6 @@ function testEventsConnect() {
});
}

function testEventsConnectPoolCluster() {
const poolCluster = createPoolCluster();
let events = 0;
/* eslint-disable no-invalid-this */
poolCluster
.once('warn', function () {
assert.equal(this, poolCluster);
++events;
})
.once('remove', function () {
assert.equal(this, poolCluster);
++events;
eventsPoolCluster = events === 2;
});
/* eslint-enable no-invalid-this */
poolCluster.poolCluster.emit('warn', new Error());
poolCluster.poolCluster.emit("remove");

}

function testBasicPool() {
const pool = createPool(config);
const promiseConn = pool.getConnection();
Expand Down Expand Up @@ -491,7 +469,6 @@ testBasicPool();
testErrorsPool();
testObjParamsPool();
testEventsPool();
testEventsConnectPoolCluster();
testChangeUser();
testConnectionProperties();
testPoolConnectionDestroy();
Expand All @@ -501,7 +478,6 @@ process.on('exit', () => {
assert.equal(doneCalled, true, 'done not called');
assert.equal(exceptionCaught, true, 'exception not caught');
assert.equal(doneEventsConnect, true, 'wrong number of connection events');
assert.equal(eventsPoolCluster, true, 'wrong number of pool cluster events');
assert.equal(doneCalledPool, true, 'pool done not called');
assert.equal(exceptionCaughtPool, true, 'pool exception not caught');
assert.equal(doneEventsPool, true, 'wrong number of pool connection events');
Expand Down

0 comments on commit 588b875

Please sign in to comment.