Skip to content

Commit

Permalink
test: Investigate flaky tests by turning off tests randomizer (#9181)
Browse files Browse the repository at this point in the history
  • Loading branch information
dplewis authored Jul 7, 2024
1 parent 2ecc5a5 commit e7199e8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions spec/ParseAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
37 changes: 22 additions & 15 deletions spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ const defaultConfiguration = {
directAccess: true,
silent,
logLevel,
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
fileUpload: {
enableForPublic: true,
enableForAnonymousUser: true,
Expand All @@ -134,6 +138,7 @@ const defaultConfiguration = {
shortLivedAuth: mockShortLivedAuth(),
},
allowClientClassCreation: true,
encodeParseObjectInCloudFunction: true,
};

if (silent) {
Expand Down Expand Up @@ -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;
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion spec/support/jasmine.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"spec_dir": "spec",
"spec_files": ["*spec.js"],
"helpers": ["helper.js"],
"random": true
"random": false
}

0 comments on commit e7199e8

Please sign in to comment.