Updates tests to allow calls that race to create a schema to have
the race loser return before the race winner. This test failed in mongo 2.6.11, and I don't know if thats because it's generally flaky or if that version of mongo makes less guarantees.
This commit is contained in:
@@ -170,19 +170,13 @@ describe('Schema', () => {
|
|||||||
|
|
||||||
it('will resolve class creation races appropriately', done => {
|
it('will resolve class creation races appropriately', done => {
|
||||||
// If two callers race to create the same schema, the response to the
|
// If two callers race to create the same schema, the response to the
|
||||||
// loser should be the same as if they hadn't been racing. Furthermore,
|
// race loser should be the same as if they hadn't been racing.
|
||||||
// The caller that wins the race should resolve it's promise before the
|
|
||||||
// caller that loses the race.
|
|
||||||
config.database.loadSchema()
|
config.database.loadSchema()
|
||||||
.then(schema => {
|
.then(schema => {
|
||||||
var p1 = schema.addClassIfNotExists('NewClass', {foo: {type: 'String'}});
|
var p1 = schema.addClassIfNotExists('NewClass', {foo: {type: 'String'}});
|
||||||
var p2 = schema.addClassIfNotExists('NewClass', {foo: {type: 'String'}});
|
var p2 = schema.addClassIfNotExists('NewClass', {foo: {type: 'String'}});
|
||||||
var raceWinnerHasSucceeded = false;
|
|
||||||
var raceLoserHasFailed = false;
|
|
||||||
Promise.race([p1, p2]) //Use race because we expect the first completed promise to be the successful one
|
Promise.race([p1, p2]) //Use race because we expect the first completed promise to be the successful one
|
||||||
.then(response => {
|
.then(response => {
|
||||||
raceWinnerHasSucceeded = true;
|
|
||||||
expect(raceLoserHasFailed).toEqual(false);
|
|
||||||
expect(response).toEqual({
|
expect(response).toEqual({
|
||||||
_id: 'NewClass',
|
_id: 'NewClass',
|
||||||
objectId: 'string',
|
objectId: 'string',
|
||||||
@@ -193,11 +187,9 @@ describe('Schema', () => {
|
|||||||
});
|
});
|
||||||
Promise.all([p1,p2])
|
Promise.all([p1,p2])
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
expect(raceWinnerHasSucceeded).toEqual(true);
|
|
||||||
expect(error.code).toEqual(Parse.Error.INVALID_CLASS_NAME);
|
expect(error.code).toEqual(Parse.Error.INVALID_CLASS_NAME);
|
||||||
expect(error.error).toEqual('class NewClass already exists');
|
expect(error.error).toEqual('class NewClass already exists');
|
||||||
done();
|
done();
|
||||||
raceLoserHasFailed = true;
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user