From 5306e6bdf2cd05a78830a287c4ef7a7872f05cd8 Mon Sep 17 00:00:00 2001
From: Michael Kriese <michael.kriese@visualon.de>
Date: Thu, 25 Apr 2019 14:43:21 +0200
Subject: [PATCH] fix(bitbucket-server): fix race condition (#3592)

---
 lib/platform/bitbucket-server/index.js       | 4 ++++
 test/platform/bitbucket-server/index.spec.js | 1 +
 2 files changed, 5 insertions(+)

diff --git a/lib/platform/bitbucket-server/index.js b/lib/platform/bitbucket-server/index.js
index 5e96c53d2f..77ca73f54f 100644
--- a/lib/platform/bitbucket-server/index.js
+++ b/lib/platform/bitbucket-server/index.js
@@ -1,4 +1,5 @@
 const url = require('url');
+const delay = require('delay');
 
 const api = require('./bb-got-wrapper');
 const utils = require('./utils');
@@ -240,6 +241,8 @@ async function commitFilesToBranch(
     parentBranch
   );
 
+  // wait for pr change propagation
+  await delay(1000);
   // refresh cache
   await getBranchPr(branchName, true);
 }
@@ -696,6 +699,7 @@ async function getPr(prNo, refreshCache) {
   if (!prNo) {
     return null;
   }
+
   const res = await api.get(
     `./rest/api/1.0/projects/${config.projectKey}/repos/${
       config.repositorySlug
diff --git a/test/platform/bitbucket-server/index.spec.js b/test/platform/bitbucket-server/index.spec.js
index 6ceaa386e3..eb92d65528 100644
--- a/test/platform/bitbucket-server/index.spec.js
+++ b/test/platform/bitbucket-server/index.spec.js
@@ -13,6 +13,7 @@ describe('platform/bitbucket-server', () => {
       beforeEach(() => {
         // reset module
         jest.resetModules();
+        jest.mock('delay');
         jest.mock('got', () => (url, options) => {
           const { method } = options;
           const body = mockResponses[url] && mockResponses[url][method];
-- 
GitLab