Fix flaky test with transactions (#7187)
* Fix flaky test with transactions * Add CHANGELOG entry * Fix the other transactions related tests that became flaky because now Parse Server tries to submit the transaction multilpe times in the case of TransientError * Remove fit from tests
This commit is contained in:
committed by
GitHub
parent
9a9fc5fa5f
commit
a430d6f7b7
@@ -48,44 +48,60 @@ function ParseServerRESTController(applicationId, router) {
|
||||
}
|
||||
|
||||
if (path === '/batch') {
|
||||
let initialPromise = Promise.resolve();
|
||||
if (data.transaction === true) {
|
||||
initialPromise = config.database.createTransactionalSession();
|
||||
}
|
||||
return initialPromise.then(() => {
|
||||
const promises = data.requests.map(request => {
|
||||
return handleRequest(request.method, request.path, request.body, options, config).then(
|
||||
response => {
|
||||
if (options.returnStatus) {
|
||||
const status = response._status;
|
||||
delete response._status;
|
||||
return { success: response, _status: status };
|
||||
const batch = transactionRetries => {
|
||||
let initialPromise = Promise.resolve();
|
||||
if (data.transaction === true) {
|
||||
initialPromise = config.database.createTransactionalSession();
|
||||
}
|
||||
return initialPromise.then(() => {
|
||||
const promises = data.requests.map(request => {
|
||||
return handleRequest(request.method, request.path, request.body, options, config).then(
|
||||
response => {
|
||||
if (options.returnStatus) {
|
||||
const status = response._status;
|
||||
delete response._status;
|
||||
return { success: response, _status: status };
|
||||
}
|
||||
return { success: response };
|
||||
},
|
||||
error => {
|
||||
return {
|
||||
error: { code: error.code, error: error.message },
|
||||
};
|
||||
}
|
||||
return { success: response };
|
||||
},
|
||||
error => {
|
||||
return {
|
||||
error: { code: error.code, error: error.message },
|
||||
};
|
||||
}
|
||||
);
|
||||
});
|
||||
return Promise.all(promises).then(result => {
|
||||
if (data.transaction === true) {
|
||||
if (result.find(resultItem => typeof resultItem.error === 'object')) {
|
||||
return config.database.abortTransactionalSession().then(() => {
|
||||
return Promise.reject(result);
|
||||
});
|
||||
} else {
|
||||
return config.database.commitTransactionalSession().then(() => {
|
||||
);
|
||||
});
|
||||
return Promise.all(promises)
|
||||
.then(result => {
|
||||
if (data.transaction === true) {
|
||||
if (result.find(resultItem => typeof resultItem.error === 'object')) {
|
||||
return config.database.abortTransactionalSession().then(() => {
|
||||
return Promise.reject(result);
|
||||
});
|
||||
} else {
|
||||
return config.database.commitTransactionalSession().then(() => {
|
||||
return result;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return result;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if (
|
||||
error &&
|
||||
error.find(
|
||||
errorItem => typeof errorItem.error === 'object' && errorItem.error.code === 251
|
||||
) &&
|
||||
transactionRetries > 0
|
||||
) {
|
||||
return batch(transactionRetries - 1);
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
return batch(5);
|
||||
}
|
||||
|
||||
let query;
|
||||
|
||||
Reference in New Issue
Block a user