From 1088415d44d6261e06ae9bb9594028b2df555d81 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Sat, 6 Jul 2024 21:34:32 -0500 Subject: [PATCH 1/4] testing server --- spec/helper.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/helper.js b/spec/helper.js index 6b9db05cf2..3c2a060500 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -180,6 +180,12 @@ const reconfigureServer = async (changedConfiguration = {}) => { }); cache.clear(); const parseServer = await ParseServer.startApp(newConfiguration); + console.log(parseServer.config.state); + if (parseServer.config.state === 'initialized') { + console.log(newConfiguration); + console.error('Failed to initialize Parse Server'); + return reconfigureServer(newConfiguration); + } server = parseServer.server; Parse.CoreManager.setRESTController(RESTController); parseServer.expressApp.use('/1', err => { From 0981f1122938d733f4bac93a7254d732525114cb Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Sat, 6 Jul 2024 21:48:24 -0500 Subject: [PATCH 2/4] debug closure --- spec/helper.js | 4 ++-- spec/support/jasmine.json | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/spec/helper.js b/spec/helper.js index 3c2a060500..fef5463c57 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -227,9 +227,9 @@ beforeEach(() => { afterEach(function (done) { const afterLogOut = async () => { if (Object.keys(openConnections).length > 0) { - console.warn('There were open connections to the server left after the test finished'); + console.warn(`There were ${Object.keys(openConnections).length} open connections to the server left after the test finished`); } - destroyAliveConnections(); + // destroyAliveConnections(); await TestUtils.destroyAllDataPermanently(true); SchemaCache.clear(); if (didChangeConfiguration) { diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json index 84d7629c1b..c5bafa2479 100644 --- a/spec/support/jasmine.json +++ b/spec/support/jasmine.json @@ -1,6 +1,5 @@ { "spec_dir": "spec", "spec_files": ["*spec.js"], - "helpers": ["helper.js"], - "random": true + "helpers": ["helper.js"] } From fbd4e098db316e21ffedb6245d024f154f914e20 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Sun, 7 Jul 2024 15:10:57 -0500 Subject: [PATCH 3/4] Update ParseLiveQuery.spec.js --- spec/ParseLiveQuery.spec.js | 2 +- spec/helper.js | 116 ++++++++++++++++-------------------- src/ParseServer.js | 6 ++ 3 files changed, 60 insertions(+), 64 deletions(-) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index 789898f62a..f072546403 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -619,7 +619,7 @@ describe('ParseLiveQuery', function () { await object.save(); }); - it('can handle beforeConnect error', async () => { + fit('can handle beforeConnect error', async () => { await reconfigureServer({ liveQuery: { classNames: ['TestObject'], diff --git a/spec/helper.js b/spec/helper.js index fef5463c57..5db820c562 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -162,15 +162,15 @@ const destroyAliveConnections = function () { } }; // Set up a default API server for testing with default configuration. -let server; - +let parseServer; let didChangeConfiguration = false; // Allows testing specific configurations of Parse Server const reconfigureServer = async (changedConfiguration = {}) => { - if (server) { - await new Promise(resolve => server.close(resolve)); - server = undefined; + if (parseServer) { + destroyAliveConnections(); + await new Promise(resolve => parseServer.server.close(resolve)); + parseServer = undefined; return reconfigureServer(changedConfiguration); } didChangeConfiguration = Object.keys(changedConfiguration).length !== 0; @@ -179,20 +179,28 @@ const reconfigureServer = async (changedConfiguration = {}) => { port, }); cache.clear(); - const parseServer = await ParseServer.startApp(newConfiguration); + parseServer = await ParseServer.startApp(newConfiguration); console.log(parseServer.config.state); if (parseServer.config.state === 'initialized') { console.log(newConfiguration); console.error('Failed to initialize Parse Server'); return reconfigureServer(newConfiguration); } - server = parseServer.server; Parse.CoreManager.setRESTController(RESTController); parseServer.expressApp.use('/1', err => { console.error(err); fail('should not call next'); }); - server.on('connection', connection => { + // parseServer.server.on('close', () => { + // console.log('why we closed'); + // }); + // parseServer.server.on('error', () => { + // console.log('why we error'); + // }); + // parseServer.server.on('shutdown', () => { + // console.log('why we error'); + // }); + parseServer.server.on('connection', connection => { const key = `${connection.remoteAddress}:${connection.remotePort}`; openConnections[key] = connection; connection.on('close', () => { @@ -224,64 +232,46 @@ beforeEach(() => { jasmine.DEFAULT_TIMEOUT_INTERVAL = process.env.PARSE_SERVER_TEST_TIMEOUT || 10000; }); -afterEach(function (done) { - const afterLogOut = async () => { - if (Object.keys(openConnections).length > 0) { - console.warn(`There were ${Object.keys(openConnections).length} open connections to the server left after the test finished`); - } - // destroyAliveConnections(); - await TestUtils.destroyAllDataPermanently(true); - SchemaCache.clear(); - if (didChangeConfiguration) { - await reconfigureServer(); - } else { - await databaseAdapter.performInitialization({ VolatileClassesSchemas }); - } - done(); - }; +afterEach(async () => { Parse.Cloud._removeAllHooks(); Parse.CoreManager.getLiveQueryController().setDefaultLiveQueryClient(); defaults.protectedFields = { _User: { '*': ['email'] } }; - databaseAdapter - .getAllClasses() - .then(allSchemas => { - allSchemas.forEach(schema => { - const className = schema.className; - expect(className).toEqual({ - asymmetricMatch: className => { - if (!className.startsWith('_')) { - return true; - } else { - // Other system classes will break Parse.com, so make sure that we don't save anything to _SCHEMA that will - // break it. - return ( - [ - '_User', - '_Installation', - '_Role', - '_Session', - '_Product', - '_Audience', - '_Idempotency', - ].indexOf(className) >= 0 - ); - } - }, - }); - }); - }) - .then(() => Parse.User.logOut()) - .then( - () => {}, - () => {} - ) // swallow errors - .then(() => { - // Connection close events are not immediate on node 10+... wait a bit - return new Promise(resolve => { - setTimeout(resolve, 0); - }); - }) - .then(afterLogOut); + const allSchemas = await databaseAdapter.getAllClasses(); + allSchemas.forEach(schema => { + const className = schema.className; + expect(className).toEqual({ + asymmetricMatch: className => { + if (!className.startsWith('_')) { + return true; + } else { + // Other system classes will break Parse.com, so make sure that we don't save anything to _SCHEMA that will + // break it. + return ( + [ + '_User', + '_Installation', + '_Role', + '_Session', + '_Product', + '_Audience', + '_Idempotency', + ].indexOf(className) >= 0 + ); + } + }, + }); + }); + await Parse.User.logOut(); + if (Object.keys(openConnections).length > 0) { + console.warn(`There were ${Object.keys(openConnections).length} open connections to the server left after the test finished`); + } + await TestUtils.destroyAllDataPermanently(true); + SchemaCache.clear(); + if (didChangeConfiguration) { + await reconfigureServer(); + } else { + await databaseAdapter.performInitialization({ VolatileClassesSchemas }); + } }); const TestObject = Parse.Object.extend({ diff --git a/src/ParseServer.js b/src/ParseServer.js index e8c7078a90..bd0be36c2e 100644 --- a/src/ParseServer.js +++ b/src/ParseServer.js @@ -227,11 +227,17 @@ class ParseServer { promises.push(cacheAdapter.handleShutdown()); } if (this.liveQueryServer?.server?.close) { + console.log(this.liveQueryServer?.server); + this.liveQueryServer?.server.getConnections((err, count) => { + console.log('Connections: ', count, err); + }); promises.push(new Promise(resolve => this.liveQueryServer.server.close(resolve))); } if (this.liveQueryServer) { promises.push(this.liveQueryServer.shutdown()); } + console.log('Shutting down Parse Server'); + console.log(promises.length); return (promises.length > 0 ? Promise.all(promises) : Promise.resolve()).then(() => { if (this.config.serverCloseComplete) { this.config.serverCloseComplete(); From d20f59311c22a4074b09a2b300a558eb6b61b636 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Sun, 7 Jul 2024 15:11:48 -0500 Subject: [PATCH 4/4] Update ParseLiveQuery.spec.js --- spec/ParseLiveQuery.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/ParseLiveQuery.spec.js b/spec/ParseLiveQuery.spec.js index f072546403..789898f62a 100644 --- a/spec/ParseLiveQuery.spec.js +++ b/spec/ParseLiveQuery.spec.js @@ -619,7 +619,7 @@ describe('ParseLiveQuery', function () { await object.save(); }); - fit('can handle beforeConnect error', async () => { + it('can handle beforeConnect error', async () => { await reconfigureServer({ liveQuery: { classNames: ['TestObject'],