From 588b875cc0e7d981aea4da6197f6e03e54ae8b22 Mon Sep 17 00:00:00 2001 From: Michael Booth Date: Mon, 10 Jul 2023 20:13:51 +0100 Subject: [PATCH] Move pool cluster promise test to builtin-runner --- .../pool-cluster/test-promise-wrapper.mjs | 33 +++++++++++++++++++ .../promise-wrappers/test-promise-wrappers.js | 24 -------------- 2 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 test/builtin-runner/integration/pool-cluster/test-promise-wrapper.mjs diff --git a/test/builtin-runner/integration/pool-cluster/test-promise-wrapper.mjs b/test/builtin-runner/integration/pool-cluster/test-promise-wrapper.mjs new file mode 100644 index 0000000000..b66a661a27 --- /dev/null +++ b/test/builtin-runner/integration/pool-cluster/test-promise-wrapper.mjs @@ -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'); + }); +}); diff --git a/test/integration/promise-wrappers/test-promise-wrappers.js b/test/integration/promise-wrappers/test-promise-wrappers.js index f39be627b9..6a1fc17448 100644 --- a/test/integration/promise-wrappers/test-promise-wrappers.js +++ b/test/integration/promise-wrappers/test-promise-wrappers.js @@ -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; @@ -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; @@ -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(); @@ -491,7 +469,6 @@ testBasicPool(); testErrorsPool(); testObjParamsPool(); testEventsPool(); -testEventsConnectPoolCluster(); testChangeUser(); testConnectionProperties(); testPoolConnectionDestroy(); @@ -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');