Skip to content

Commit

Permalink
Fixed deadlock when adding multiple authors in tests
Browse files Browse the repository at this point in the history
refs 275107d

- 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
  • Loading branch information
naz committed May 3, 2022
1 parent 275107d commit 734ef66
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/utils/fixture-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down

0 comments on commit 734ef66

Please sign in to comment.