From e7199e8d07350d47634986f51b0a46f3ca0fbde2 Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Sun, 7 Jul 2024 18:20:28 -0500 Subject: [PATCH] test: Investigate flaky tests by turning off tests randomizer (#9181) --- spec/CloudCode.spec.js | 1 + spec/ParseAPI.spec.js | 1 + spec/helper.js | 37 ++++++++++++++++++++++--------------- spec/support/jasmine.json | 2 +- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index 239a58d39f..fcfeba416b 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -1362,6 +1362,7 @@ describe('Cloud Code', () => { }); it('should not encode Parse Objects', async () => { + await reconfigureServer({ encodeParseObjectInCloudFunction: false }); const user = new Parse.User(); user.setUsername('username'); user.setPassword('password'); diff --git a/spec/ParseAPI.spec.js b/spec/ParseAPI.spec.js index 4f8190a4a6..58c1134bb1 100644 --- a/spec/ParseAPI.spec.js +++ b/spec/ParseAPI.spec.js @@ -1268,6 +1268,7 @@ describe('miscellaneous', function () { }); it('test cloud function query parameters with array of pointers', async () => { + await reconfigureServer({ encodeParseObjectInCloudFunction: false }); Parse.Cloud.define('echoParams', req => { return req.params; }); diff --git a/spec/helper.js b/spec/helper.js index 6b9db05cf2..d9ced55ede 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -113,6 +113,10 @@ const defaultConfiguration = { directAccess: true, silent, logLevel, + liveQuery: { + classNames: ['TestObject'], + }, + startLiveQueryServer: true, fileUpload: { enableForPublic: true, enableForAnonymousUser: true, @@ -134,6 +138,7 @@ const defaultConfiguration = { shortLivedAuth: mockShortLivedAuth(), }, allowClientClassCreation: true, + encodeParseObjectInCloudFunction: true, }; if (silent) { @@ -162,15 +167,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 +184,20 @@ const reconfigureServer = async (changedConfiguration = {}) => { port, }); cache.clear(); - const parseServer = await ParseServer.startApp(newConfiguration); - server = parseServer.server; + parseServer = await ParseServer.startApp(newConfiguration); Parse.CoreManager.setRESTController(RESTController); parseServer.expressApp.use('/1', err => { console.error(err); fail('should not call next'); }); - server.on('connection', connection => { + parseServer.liveQueryServer?.server?.on('connection', connection => { + const key = `${connection.remoteAddress}:${connection.remotePort}`; + openConnections[key] = connection; + connection.on('close', () => { + delete openConnections[key]; + }); + }); + parseServer.server.on('connection', connection => { const key = `${connection.remoteAddress}:${connection.remotePort}`; openConnections[key] = connection; connection.on('close', () => { @@ -214,16 +225,12 @@ beforeAll(async () => { Parse.serverURL = 'http://localhost:' + port + '/1'; }); -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'); + // Jasmine process uses one connection + if (Object.keys(openConnections).length > 1) { + 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) { diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json index 84d7629c1b..1fbe0c31bf 100644 --- a/spec/support/jasmine.json +++ b/spec/support/jasmine.json @@ -2,5 +2,5 @@ "spec_dir": "spec", "spec_files": ["*spec.js"], "helpers": ["helper.js"], - "random": true + "random": false }