test: Investigate flaky tests by turning off tests randomizer (#9181)

This commit is contained in:
Diamond Lewis
2024-07-07 18:20:28 -05:00
committed by GitHub
parent 2ecc5a5bf5
commit e7199e8d07
4 changed files with 25 additions and 16 deletions

View File

@@ -1362,6 +1362,7 @@ describe('Cloud Code', () => {
}); });
it('should not encode Parse Objects', async () => { it('should not encode Parse Objects', async () => {
await reconfigureServer({ encodeParseObjectInCloudFunction: false });
const user = new Parse.User(); const user = new Parse.User();
user.setUsername('username'); user.setUsername('username');
user.setPassword('password'); user.setPassword('password');

View File

@@ -1268,6 +1268,7 @@ describe('miscellaneous', function () {
}); });
it('test cloud function query parameters with array of pointers', async () => { it('test cloud function query parameters with array of pointers', async () => {
await reconfigureServer({ encodeParseObjectInCloudFunction: false });
Parse.Cloud.define('echoParams', req => { Parse.Cloud.define('echoParams', req => {
return req.params; return req.params;
}); });

View File

@@ -113,6 +113,10 @@ const defaultConfiguration = {
directAccess: true, directAccess: true,
silent, silent,
logLevel, logLevel,
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
fileUpload: { fileUpload: {
enableForPublic: true, enableForPublic: true,
enableForAnonymousUser: true, enableForAnonymousUser: true,
@@ -134,6 +138,7 @@ const defaultConfiguration = {
shortLivedAuth: mockShortLivedAuth(), shortLivedAuth: mockShortLivedAuth(),
}, },
allowClientClassCreation: true, allowClientClassCreation: true,
encodeParseObjectInCloudFunction: true,
}; };
if (silent) { if (silent) {
@@ -162,15 +167,15 @@ const destroyAliveConnections = function () {
} }
}; };
// Set up a default API server for testing with default configuration. // Set up a default API server for testing with default configuration.
let server; let parseServer;
let didChangeConfiguration = false; let didChangeConfiguration = false;
// Allows testing specific configurations of Parse Server // Allows testing specific configurations of Parse Server
const reconfigureServer = async (changedConfiguration = {}) => { const reconfigureServer = async (changedConfiguration = {}) => {
if (server) { if (parseServer) {
await new Promise(resolve => server.close(resolve)); destroyAliveConnections();
server = undefined; await new Promise(resolve => parseServer.server.close(resolve));
parseServer = undefined;
return reconfigureServer(changedConfiguration); return reconfigureServer(changedConfiguration);
} }
didChangeConfiguration = Object.keys(changedConfiguration).length !== 0; didChangeConfiguration = Object.keys(changedConfiguration).length !== 0;
@@ -179,14 +184,20 @@ const reconfigureServer = async (changedConfiguration = {}) => {
port, port,
}); });
cache.clear(); cache.clear();
const parseServer = await ParseServer.startApp(newConfiguration); parseServer = await ParseServer.startApp(newConfiguration);
server = parseServer.server;
Parse.CoreManager.setRESTController(RESTController); Parse.CoreManager.setRESTController(RESTController);
parseServer.expressApp.use('/1', err => { parseServer.expressApp.use('/1', err => {
console.error(err); console.error(err);
fail('should not call next'); 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}`; const key = `${connection.remoteAddress}:${connection.remotePort}`;
openConnections[key] = connection; openConnections[key] = connection;
connection.on('close', () => { connection.on('close', () => {
@@ -214,16 +225,12 @@ beforeAll(async () => {
Parse.serverURL = 'http://localhost:' + port + '/1'; Parse.serverURL = 'http://localhost:' + port + '/1';
}); });
beforeEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = process.env.PARSE_SERVER_TEST_TIMEOUT || 10000;
});
afterEach(function (done) { afterEach(function (done) {
const afterLogOut = async () => { const afterLogOut = async () => {
if (Object.keys(openConnections).length > 0) { // Jasmine process uses one connection
console.warn('There were open connections to the server left after the test finished'); 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); await TestUtils.destroyAllDataPermanently(true);
SchemaCache.clear(); SchemaCache.clear();
if (didChangeConfiguration) { if (didChangeConfiguration) {

View File

@@ -2,5 +2,5 @@
"spec_dir": "spec", "spec_dir": "spec",
"spec_files": ["*spec.js"], "spec_files": ["*spec.js"],
"helpers": ["helper.js"], "helpers": ["helper.js"],
"random": true "random": false
} }