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
91
src/batch.js
91
src/batch.js
@@ -83,49 +83,66 @@ function handleBatch(router, req) {
|
||||
req.config.publicServerURL
|
||||
);
|
||||
|
||||
let initialPromise = Promise.resolve();
|
||||
if (req.body.transaction === true) {
|
||||
initialPromise = req.config.database.createTransactionalSession();
|
||||
}
|
||||
const batch = transactionRetries => {
|
||||
let initialPromise = Promise.resolve();
|
||||
if (req.body.transaction === true) {
|
||||
initialPromise = req.config.database.createTransactionalSession();
|
||||
}
|
||||
|
||||
return initialPromise.then(() => {
|
||||
const promises = req.body.requests.map(restRequest => {
|
||||
const routablePath = makeRoutablePath(restRequest.path);
|
||||
return initialPromise.then(() => {
|
||||
const promises = req.body.requests.map(restRequest => {
|
||||
const routablePath = makeRoutablePath(restRequest.path);
|
||||
|
||||
// Construct a request that we can send to a handler
|
||||
const request = {
|
||||
body: restRequest.body,
|
||||
config: req.config,
|
||||
auth: req.auth,
|
||||
info: req.info,
|
||||
};
|
||||
// Construct a request that we can send to a handler
|
||||
const request = {
|
||||
body: restRequest.body,
|
||||
config: req.config,
|
||||
auth: req.auth,
|
||||
info: req.info,
|
||||
};
|
||||
|
||||
return router.tryRouteRequest(restRequest.method, routablePath, request).then(
|
||||
response => {
|
||||
return { success: response.response };
|
||||
},
|
||||
error => {
|
||||
return { error: { code: error.code, error: error.message } };
|
||||
}
|
||||
);
|
||||
});
|
||||
return router.tryRouteRequest(restRequest.method, routablePath, request).then(
|
||||
response => {
|
||||
return { success: response.response };
|
||||
},
|
||||
error => {
|
||||
return { error: { code: error.code, error: error.message } };
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(results => {
|
||||
if (req.body.transaction === true) {
|
||||
if (results.find(result => typeof result.error === 'object')) {
|
||||
return req.config.database.abortTransactionalSession().then(() => {
|
||||
return Promise.reject({ response: results });
|
||||
});
|
||||
} else {
|
||||
return req.config.database.commitTransactionalSession().then(() => {
|
||||
return Promise.all(promises)
|
||||
.then(results => {
|
||||
if (req.body.transaction === true) {
|
||||
if (results.find(result => typeof result.error === 'object')) {
|
||||
return req.config.database.abortTransactionalSession().then(() => {
|
||||
return Promise.reject({ response: results });
|
||||
});
|
||||
} else {
|
||||
return req.config.database.commitTransactionalSession().then(() => {
|
||||
return { response: results };
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return { response: results };
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return { response: results };
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if (
|
||||
error &&
|
||||
error.response &&
|
||||
error.response.find(
|
||||
errorItem => typeof errorItem.error === 'object' && errorItem.error.code === 251
|
||||
) &&
|
||||
transactionRetries > 0
|
||||
) {
|
||||
return batch(transactionRetries - 1);
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
return batch(5);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user