diff --git a/spec/helper.js b/spec/helper.js index 6b9db05cf2..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,14 +179,28 @@ const reconfigureServer = async (changedConfiguration = {}) => { port, }); cache.clear(); - const parseServer = await ParseServer.startApp(newConfiguration); - server = parseServer.server; + 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); + } 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', () => { @@ -218,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 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/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"] } 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();