From 63f2cfdd3218e8386a76be3998e78acd37fd93ea Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Tue, 12 Jul 2022 15:58:33 +0200 Subject: [PATCH] Fixed comments fixtures being created in parallel refs https://ghost.slack.com/archives/C02G9E68C/p1657633760754589?thread_ts=1657624324.578099&cid=C02G9E68C - The two comment fixtures are created in parallel - Second one is created while the first one doesn't exist yet, which causes a FK constraint error --- test/utils/fixture-utils.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/utils/fixture-utils.js b/test/utils/fixture-utils.js index 45f0091020..cd4bedba7e 100644 --- a/test/utils/fixture-utils.js +++ b/test/utils/fixture-utils.js @@ -610,9 +610,17 @@ const fixtures = { }, insertComments: async function insertComments() { - return Promise.map(DataGenerator.forKnex.comments, function (comment) { + // First create the parents (can happen in parallel), because the children depend on those + const parents = DataGenerator.forKnex.comments.filter(c => !c.parent_id); + const children = DataGenerator.forKnex.comments.filter(c => !!c.parent_id); + + await Promise.all(parents.map((comment) => { return models.Comment.add(comment, context.internal); - }); + })); + + await Promise.all(children.map((comment) => { + return models.Comment.add(comment, context.internal); + })); }, insertSnippets: function insertSnippets() {