# Class: Backend::Test

Inherits:
  Object
  - Object
  - Backend::Test
  show all

Defined in:
  test.rb,
  test/tasks.rb

## Overview

Class that holds methods for starting the backend server in test mode

## Defined Under Namespace

Modules: Tasks

## Class Method Summary collapse

- .do_not_start_test_backend ⇒ Object

  Avoid starting the test backend again.

- .start(options = {}) ⇒ Object

  Starts the test backend.

- .without_global_write_through ⇒ Object

  Run the block code deactivating the global_write_through flag.

## Class Method Details

### .do_not_start_test_backend ⇒ `Object`

Avoid starting the test backend again

    43
    44
    45
    # File 'test.rb', line 43

    def self.do_not_start_test_backend
      @backend = :dont
    end

### .start(options = {}) ⇒ `Object`

Starts the test backend

    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    # File 'test.rb', line 7

    def self.start(options = {})
      return unless Rails.env.test?
      return if @backend
      return if ENV['BACKEND_STARTED']
      print 'Starting test backend...'
      @backend = IO.popen("#{Rails.root}/script/start_test_backend")
      Rails.logger.debug "Test backend started with pid: #{@backend.pid}"
      loop do
        line = @backend.gets
        raise 'Backend died' unless line
        break if line =~ /DONE NOW/
        Rails.logger.debug line.strip
      end
      puts 'done'
      CONFIG['global_write_through'] = true
      WebMock.disable_net_connect!(allow_localhost: true)
      ENV['BACKEND_STARTED'] = '1'
      at_exit do
        puts 'Killing test backend'
        Process.kill 'INT', @backend.pid
        @backend = nil
      end

      # make sure it's actually tried to start
      return unless options[:wait_for_scheduler]
      Rails.logger.debug 'Wait for scheduler thread to finish start'
      counter = 0
      marker = Rails.root.join('tmp', 'scheduler.done')
      while counter < 100
        return if ::File.exist?(marker)
        sleep 0.5
        counter += 1
      end
    end

### .without_global_write_through ⇒ `Object`

Run the block code deactivating the global_write_through flag

    48
    49
    50
    51
    52
    53
    54
    # File 'test.rb', line 48

    def self.without_global_write_through
      before = CONFIG['global_write_through']
      CONFIG['global_write_through'] = false
      yield
    ensure
      CONFIG['global_write_through'] = before
    end