From 734ef66e6ce9868fe2143046cb56cdc8e4216ff5 Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 3 May 2022 16:28:07 +0800 Subject: [PATCH] Fixed deadlock when adding multiple authors in tests refs https://github.com/TryGhost/Ghost/commit/275107d423bfb64e5885a5247244969173453016 - Because there might be multiple authors being added at the same time with different values to the posts_authors table these operations should not be done in parallel! Making post insertion sequential fixed the deadlock --- test/utils/fixture-utils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/utils/fixture-utils.js b/test/utils/fixture-utils.js index ce266381bea..b56f8e1af7b 100644 --- a/test/utils/fixture-utils.js +++ b/test/utils/fixture-utils.js @@ -6,6 +6,7 @@ const fs = require('fs-extra'); const uuid = require('uuid'); const ObjectId = require('bson-objectid'); const KnexMigrator = require('knex-migrator'); +const {sequence} = require('@tryghost/promise'); const knexMigrator = new KnexMigrator(); // Ghost Internals @@ -26,9 +27,11 @@ let postsInserted = 0; /** TEST FIXTURES **/ const fixtures = { insertPosts: function insertPosts(posts) { - return Promise.map(posts, function (post) { + const tasks = posts.map(post => () => { return models.Post.add(post, context.internal); }); + + return sequence(tasks); }, insertPostsAndTags: function insertPostsAndTags() {