Remove test delays (#5579)
* Changing __indexBuildCompletionCallbackForTests callback to serverStartComplete * Improving serverStartComplete callback to avoid production unhandled promise rejection * Add test to check inexistence of unhandled promise rejection on server fail * Removing some hooks delays * Removing delay after reconfigureServer * Improving code style
This commit is contained in:
committed by
GitHub
parent
2f161c25cd
commit
893f1d376e
@@ -453,13 +453,13 @@ describe('Cloud Code', () => {
|
|||||||
Parse.Cloud.afterSave('AfterSaveTest', function(req) {
|
Parse.Cloud.afterSave('AfterSaveTest', function(req) {
|
||||||
const obj = new Parse.Object('AfterSaveProof');
|
const obj = new Parse.Object('AfterSaveProof');
|
||||||
obj.set('proof', req.object.id);
|
obj.set('proof', req.object.id);
|
||||||
obj.save();
|
obj.save().then(test);
|
||||||
});
|
});
|
||||||
|
|
||||||
const obj = new Parse.Object('AfterSaveTest');
|
const obj = new Parse.Object('AfterSaveTest');
|
||||||
obj.save();
|
obj.save();
|
||||||
|
|
||||||
setTimeout(function() {
|
function test() {
|
||||||
const query = new Parse.Query('AfterSaveProof');
|
const query = new Parse.Query('AfterSaveProof');
|
||||||
query.equalTo('proof', obj.id);
|
query.equalTo('proof', obj.id);
|
||||||
query.find().then(
|
query.find().then(
|
||||||
@@ -472,7 +472,7 @@ describe('Cloud Code', () => {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, 500);
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test afterSave ran on created object and returned a promise', function(done) {
|
it('test afterSave ran on created object and returned a promise', function(done) {
|
||||||
@@ -729,7 +729,7 @@ describe('Cloud Code', () => {
|
|||||||
Parse.Cloud.afterDelete('AfterDeleteTest', function(req) {
|
Parse.Cloud.afterDelete('AfterDeleteTest', function(req) {
|
||||||
const obj = new Parse.Object('AfterDeleteProof');
|
const obj = new Parse.Object('AfterDeleteProof');
|
||||||
obj.set('proof', req.object.id);
|
obj.set('proof', req.object.id);
|
||||||
obj.save();
|
obj.save().then(test);
|
||||||
});
|
});
|
||||||
|
|
||||||
const obj = new Parse.Object('AfterDeleteTest');
|
const obj = new Parse.Object('AfterDeleteTest');
|
||||||
@@ -737,7 +737,7 @@ describe('Cloud Code', () => {
|
|||||||
obj.destroy();
|
obj.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(function() {
|
function test() {
|
||||||
const query = new Parse.Query('AfterDeleteProof');
|
const query = new Parse.Query('AfterDeleteProof');
|
||||||
query.equalTo('proof', obj.id);
|
query.equalTo('proof', obj.id);
|
||||||
query.find().then(
|
query.find().then(
|
||||||
@@ -750,7 +750,7 @@ describe('Cloud Code', () => {
|
|||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}, 500);
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test cloud function return types', function(done) {
|
it('test cloud function return types', function(done) {
|
||||||
|
|||||||
@@ -17,47 +17,45 @@ describe('Enable express error handler', () => {
|
|||||||
masterKey: masterKey,
|
masterKey: masterKey,
|
||||||
serverURL: serverUrl,
|
serverURL: serverUrl,
|
||||||
enableExpressErrorHandler: true,
|
enableExpressErrorHandler: true,
|
||||||
__indexBuildCompletionCallbackForTests: promise => {
|
serverStartComplete: () => {
|
||||||
promise.then(() => {
|
expect(Parse.applicationId).toEqual('anOtherTestApp');
|
||||||
expect(Parse.applicationId).toEqual('anOtherTestApp');
|
const app = express();
|
||||||
const app = express();
|
app.use('/parse', parseServer);
|
||||||
app.use('/parse', parseServer);
|
|
||||||
|
|
||||||
server = app.listen(12667);
|
server = app.listen(12667);
|
||||||
|
|
||||||
app.use(function(err, req, res, next) {
|
app.use(function(err, req, res, next) {
|
||||||
next;
|
next;
|
||||||
lastError = err;
|
lastError = err;
|
||||||
});
|
|
||||||
|
|
||||||
request({
|
|
||||||
method: 'PUT',
|
|
||||||
url: serverUrl + '/classes/AnyClass/nonExistingId',
|
|
||||||
headers: {
|
|
||||||
'X-Parse-Application-Id': appId,
|
|
||||||
'X-Parse-Master-Key': masterKey,
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: { someField: 'blablabla' },
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
fail('Should throw error');
|
|
||||||
})
|
|
||||||
.catch(response => {
|
|
||||||
const reqError = response.data;
|
|
||||||
expect(reqError).toBeDefined();
|
|
||||||
expect(lastError).toBeDefined();
|
|
||||||
|
|
||||||
expect(lastError.code).toEqual(101);
|
|
||||||
expect(lastError.message).toEqual('Object not found.');
|
|
||||||
|
|
||||||
expect(lastError.code).toEqual(reqError.code);
|
|
||||||
expect(lastError.message).toEqual(reqError.error);
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
server.close(done);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
request({
|
||||||
|
method: 'PUT',
|
||||||
|
url: serverUrl + '/classes/AnyClass/nonExistingId',
|
||||||
|
headers: {
|
||||||
|
'X-Parse-Application-Id': appId,
|
||||||
|
'X-Parse-Master-Key': masterKey,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: { someField: 'blablabla' },
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
fail('Should throw error');
|
||||||
|
})
|
||||||
|
.catch(response => {
|
||||||
|
const reqError = response.data;
|
||||||
|
expect(reqError).toBeDefined();
|
||||||
|
expect(lastError).toBeDefined();
|
||||||
|
|
||||||
|
expect(lastError.code).toEqual(101);
|
||||||
|
expect(lastError.message).toEqual('Object not found.');
|
||||||
|
|
||||||
|
expect(lastError.code).toEqual(reqError.code);
|
||||||
|
expect(lastError.message).toEqual(reqError.error);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
server.close(done);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ describe('FilesController', () => {
|
|||||||
const logController = new LoggerController(new WinstonLoggerAdapter());
|
const logController = new LoggerController(new WinstonLoggerAdapter());
|
||||||
|
|
||||||
reconfigureServer({ filesAdapter: mockAdapter })
|
reconfigureServer({ filesAdapter: mockAdapter })
|
||||||
.then(() => new Promise(resolve => setTimeout(resolve, 1000)))
|
|
||||||
.then(() => new Parse.File('yolo.txt', [1, 2, 3], 'text/plain').save())
|
.then(() => new Parse.File('yolo.txt', [1, 2, 3], 'text/plain').save())
|
||||||
.then(
|
.then(
|
||||||
() => done.fail('should not succeed'),
|
() => done.fail('should not succeed'),
|
||||||
|
|||||||
@@ -158,12 +158,10 @@ describe('ParseLiveQueryServer', function() {
|
|||||||
classNames: ['Yolo'],
|
classNames: ['Yolo'],
|
||||||
},
|
},
|
||||||
startLiveQueryServer: true,
|
startLiveQueryServer: true,
|
||||||
__indexBuildCompletionCallbackForTests: promise => {
|
serverStartComplete: () => {
|
||||||
promise.then(() => {
|
expect(parseServer.liveQueryServer).not.toBeUndefined();
|
||||||
expect(parseServer.liveQueryServer).not.toBeUndefined();
|
expect(parseServer.liveQueryServer.server).toBe(parseServer.server);
|
||||||
expect(parseServer.liveQueryServer.server).toBe(parseServer.server);
|
parseServer.server.close(done);
|
||||||
parseServer.server.close(() => done());
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -181,16 +179,14 @@ describe('ParseLiveQueryServer', function() {
|
|||||||
liveQueryServerOptions: {
|
liveQueryServerOptions: {
|
||||||
port: 22347,
|
port: 22347,
|
||||||
},
|
},
|
||||||
__indexBuildCompletionCallbackForTests: promise => {
|
serverStartComplete: () => {
|
||||||
promise.then(() => {
|
expect(parseServer.liveQueryServer).not.toBeUndefined();
|
||||||
expect(parseServer.liveQueryServer).not.toBeUndefined();
|
expect(parseServer.liveQueryServer.server).not.toBe(
|
||||||
expect(parseServer.liveQueryServer.server).not.toBe(
|
parseServer.server
|
||||||
parseServer.server
|
);
|
||||||
);
|
parseServer.liveQueryServer.server.close(
|
||||||
parseServer.liveQueryServer.server.close(() => {
|
parseServer.server.close.bind(parseServer.server, done)
|
||||||
parseServer.server.close(() => done());
|
);
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ const MongoStorageAdapter = require('../lib/Adapters/Storage/Mongo/MongoStorageA
|
|||||||
const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/PostgresStorageAdapter')
|
const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/PostgresStorageAdapter')
|
||||||
.default;
|
.default;
|
||||||
const ParseServer = require('../lib/ParseServer').default;
|
const ParseServer = require('../lib/ParseServer').default;
|
||||||
|
const path = require('path');
|
||||||
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
describe('Server Url Checks', () => {
|
describe('Server Url Checks', () => {
|
||||||
let server;
|
let server;
|
||||||
@@ -62,20 +64,38 @@ describe('Server Url Checks', () => {
|
|||||||
}
|
}
|
||||||
const newConfiguration = Object.assign({}, defaultConfiguration, {
|
const newConfiguration = Object.assign({}, defaultConfiguration, {
|
||||||
databaseAdapter,
|
databaseAdapter,
|
||||||
__indexBuildCompletionCallbackForTests: promise => {
|
serverStartComplete: () => {
|
||||||
promise.then(() => {
|
parseServer.handleShutdown();
|
||||||
parseServer.handleShutdown();
|
parseServer.server.close(err => {
|
||||||
parseServer.server.close(err => {
|
if (err) {
|
||||||
if (err) {
|
done.fail('Close Server Error');
|
||||||
done.fail('Close Server Error');
|
}
|
||||||
}
|
reconfigureServer({}).then(() => {
|
||||||
reconfigureServer({}).then(() => {
|
done();
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const parseServer = ParseServer.start(newConfiguration);
|
const parseServer = ParseServer.start(newConfiguration);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not have unhandled promise rejection in the case of load error', done => {
|
||||||
|
const parseServerProcess = spawn(
|
||||||
|
path.resolve(__dirname, './support/FailingServer.js')
|
||||||
|
);
|
||||||
|
let stdout;
|
||||||
|
let stderr;
|
||||||
|
parseServerProcess.stdout.on('data', data => {
|
||||||
|
stdout = data.toString();
|
||||||
|
});
|
||||||
|
parseServerProcess.stderr.on('data', data => {
|
||||||
|
stderr = data.toString();
|
||||||
|
});
|
||||||
|
parseServerProcess.on('close', code => {
|
||||||
|
expect(code).toEqual(1);
|
||||||
|
expect(stdout).toBeUndefined();
|
||||||
|
expect(stderr).toContain('MongoNetworkError:');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,8 +28,10 @@ function createParseServer(options) {
|
|||||||
const parseServer = new ParseServer.default(
|
const parseServer = new ParseServer.default(
|
||||||
Object.assign({}, defaultConfiguration, options, {
|
Object.assign({}, defaultConfiguration, options, {
|
||||||
serverURL: 'http://localhost:12666/parse',
|
serverURL: 'http://localhost:12666/parse',
|
||||||
__indexBuildCompletionCallbackForTests: promise => {
|
serverStartComplete: error => {
|
||||||
promise.then(() => {
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
expect(Parse.applicationId).toEqual('test');
|
expect(Parse.applicationId).toEqual('test');
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use('/parse', parseServer.app);
|
app.use('/parse', parseServer.app);
|
||||||
@@ -37,7 +39,7 @@ function createParseServer(options) {
|
|||||||
const server = app.listen(12666);
|
const server = app.listen(12666);
|
||||||
Parse.serverURL = 'http://localhost:12666/parse';
|
Parse.serverURL = 'http://localhost:12666/parse';
|
||||||
resolve(server);
|
resolve(server);
|
||||||
}, reject);
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -150,10 +150,13 @@ const reconfigureServer = changedConfiguration => {
|
|||||||
defaultConfiguration,
|
defaultConfiguration,
|
||||||
changedConfiguration,
|
changedConfiguration,
|
||||||
{
|
{
|
||||||
__indexBuildCompletionCallbackForTests: indexBuildPromise =>
|
serverStartComplete: error => {
|
||||||
indexBuildPromise.then(() => {
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
resolve(parseServer);
|
resolve(parseServer);
|
||||||
}, reject),
|
}
|
||||||
|
},
|
||||||
mountPath: '/1',
|
mountPath: '/1',
|
||||||
port,
|
port,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,30 +295,28 @@ describe('server', () => {
|
|||||||
appId: 'aTestApp',
|
appId: 'aTestApp',
|
||||||
masterKey: 'aTestMasterKey',
|
masterKey: 'aTestMasterKey',
|
||||||
serverURL: 'http://localhost:12666/parse',
|
serverURL: 'http://localhost:12666/parse',
|
||||||
__indexBuildCompletionCallbackForTests: promise => {
|
serverStartComplete: () => {
|
||||||
promise.then(() => {
|
expect(Parse.applicationId).toEqual('aTestApp');
|
||||||
expect(Parse.applicationId).toEqual('aTestApp');
|
const app = express();
|
||||||
const app = express();
|
app.use('/parse', parseServer.app);
|
||||||
app.use('/parse', parseServer.app);
|
|
||||||
|
|
||||||
const server = app.listen(12666);
|
const server = app.listen(12666);
|
||||||
const obj = new Parse.Object('AnObject');
|
const obj = new Parse.Object('AnObject');
|
||||||
let objId;
|
let objId;
|
||||||
obj
|
obj
|
||||||
.save()
|
.save()
|
||||||
.then(obj => {
|
.then(obj => {
|
||||||
objId = obj.id;
|
objId = obj.id;
|
||||||
const q = new Parse.Query('AnObject');
|
const q = new Parse.Query('AnObject');
|
||||||
return q.first();
|
return q.first();
|
||||||
})
|
})
|
||||||
.then(obj => {
|
.then(obj => {
|
||||||
expect(obj.id).toEqual(objId);
|
expect(obj.id).toEqual(objId);
|
||||||
server.close(done);
|
server.close(done);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
server.close(done);
|
server.close(done);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -332,7 +330,8 @@ describe('server', () => {
|
|||||||
appId: 'anOtherTestApp',
|
appId: 'anOtherTestApp',
|
||||||
masterKey: 'anOtherTestMasterKey',
|
masterKey: 'anOtherTestMasterKey',
|
||||||
serverURL: 'http://localhost:12667/parse',
|
serverURL: 'http://localhost:12667/parse',
|
||||||
__indexBuildCompletionCallbackForTests: promise => {
|
serverStartComplete: error => {
|
||||||
|
const promise = error ? Promise.reject(error) : Promise.resolve();
|
||||||
promise
|
promise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
expect(Parse.applicationId).toEqual('anOtherTestApp');
|
expect(Parse.applicationId).toEqual('anOtherTestApp');
|
||||||
|
|||||||
10
spec/support/FailingServer.js
Executable file
10
spec/support/FailingServer.js
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
const ParseServer = require('../../lib/index').ParseServer;
|
||||||
|
|
||||||
|
ParseServer.start({
|
||||||
|
appId: 'test',
|
||||||
|
masterKey: 'test',
|
||||||
|
databaseURI:
|
||||||
|
'mongodb://doesnotexist:27017/parseServerMongoAdapterTestDatabase',
|
||||||
|
});
|
||||||
@@ -177,7 +177,7 @@ export interface ParseServerOptions {
|
|||||||
/* Live query server configuration options (will start the liveQuery server) */
|
/* Live query server configuration options (will start the liveQuery server) */
|
||||||
liveQueryServerOptions: ?LiveQueryServerOptions;
|
liveQueryServerOptions: ?LiveQueryServerOptions;
|
||||||
|
|
||||||
__indexBuildCompletionCallbackForTests: ?() => void;
|
serverStartComplete: ?(error: ?Error) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CustomPagesOptions {
|
export interface CustomPagesOptions {
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class ParseServer {
|
|||||||
cloud,
|
cloud,
|
||||||
javascriptKey,
|
javascriptKey,
|
||||||
serverURL = requiredParameter('You must provide a serverURL!'),
|
serverURL = requiredParameter('You must provide a serverURL!'),
|
||||||
__indexBuildCompletionCallbackForTests = () => {},
|
serverStartComplete,
|
||||||
} = options;
|
} = options;
|
||||||
// Initialize the node client SDK automatically
|
// Initialize the node client SDK automatically
|
||||||
Parse.initialize(appId, javascriptKey || 'unused', masterKey);
|
Parse.initialize(appId, javascriptKey || 'unused', masterKey);
|
||||||
@@ -100,11 +100,21 @@ class ParseServer {
|
|||||||
const hooksLoadPromise = hooksController.load();
|
const hooksLoadPromise = hooksController.load();
|
||||||
|
|
||||||
// Note: Tests will start to fail if any validation happens after this is called.
|
// Note: Tests will start to fail if any validation happens after this is called.
|
||||||
if (process.env.TESTING) {
|
Promise.all([dbInitPromise, hooksLoadPromise])
|
||||||
__indexBuildCompletionCallbackForTests(
|
.then(() => {
|
||||||
Promise.all([dbInitPromise, hooksLoadPromise])
|
if (serverStartComplete) {
|
||||||
);
|
serverStartComplete();
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
if (serverStartComplete) {
|
||||||
|
serverStartComplete(error);
|
||||||
|
} else {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (cloud) {
|
if (cloud) {
|
||||||
addParseCloud();
|
addParseCloud();
|
||||||
|
|||||||
Reference in New Issue
Block a user