File obs-server-2.10-0026-ci-Actually-wait-for-scheduler-when-test-backend-is-.patch of Package obs-server

From fdf3d69ee46265c39fd9d13b38e66ff4a2e0e917 Mon Sep 17 00:00:00 2001
From: Oleg Girko <>
Date: Mon, 15 Oct 2018 01:01:02 +0100
Subject: [PATCH] [ci] Actually wait for scheduler when test backend is already

There are two ways to start test backend: waiting for scheduler startup
completion (with :wait_for_scheduler option) and not waiting
(without :wait_for_scheduler option).

The problem is that if test backend is already started without
waiting for scheduler, subsequent calls to Backend::Test.start
do nothing even with :wait_for_scheduler option.
This causes a race condition when a test needs scheduler startup
to be complete, but test backend was started earlier without waiting
for scheduler startup. The test proceeds and interferes with
scheduler startup, causing an exception in scheduler monitor thread
that crashes entire test backend.

This change fixes this problem by waiting for scheduler startup
if test backend is already started and :wait_for_scheduler option
is specified.

Signed-off-by: Oleg Girko <>
 src/api/lib/backend/test.rb | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/api/lib/backend/test.rb b/src/api/lib/backend/test.rb
index dceaf67f8f..3029f2afed 100644
--- a/src/api/lib/backend/test.rb
+++ b/src/api/lib/backend/test.rb
@@ -8,6 +8,7 @@ module Backend
       return unless Rails.env.test?
       if @backend
         raise 'Backend died' if @backend == :backend_died
+        wait_for_scheduler if options[:wait_for_scheduler] && @backend.is_a?(IO)
       return if ENV['BACKEND_STARTED']
@@ -49,6 +50,10 @@ module Backend
       # make sure it's actually tried to start
       return unless options[:wait_for_scheduler]
+      wait_for_scheduler
+    end
+    def self.wait_for_scheduler
       Rails.logger.debug 'Wait for scheduler thread to finish start'
       counter = 0
       marker = Rails.root.join('tmp', 'scheduler.done')