Class: NoidsClient::IntegrationTest::NoidServerRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/noids_client/integration_test.rb

Overview

A utility class to help running a NOIDs server within the context

Examples:

require 'noids_client/integration_test'
NoidsClient::IntegrationTest::NoidServerRunner.new do
  # thing that requires a noids server
end

Constant Summary collapse

SECONDS_TO_WAIT =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ NoidServerRunner

Returns a new instance of NoidServerRunner.

Parameters:

  • kwargs (Hash)

    the configuration options for the NoidsServer. Note, you shouldn’t need to pass parameters if you follow the noids documentation

  • logger (Hash)

    a customizable set of options

  • storage_dir (Hash)

    a customizable set of options

  • file_utils (Hash)

    a customizable set of options

  • noids_command (Hash)

    a customizable set of options

  • seconds_to_wait (Hash)

    a customizable set of options



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/noids_client/integration_test.rb', line 59

def initialize(**kwargs)
  @logger = kwargs.fetch(:logger) { IntegrationTest.default_logger }
  logger.debug("logger: #{logger.inspect}")
  @storage_dir = kwargs.fetch(:storage_dir) { default_storage_dir }
  logger.debug("storage_dir: #{storage_dir.inspect}")
  @file_utils = kwargs.fetch(:file_utils) { default_file_utils }
  logger.debug("file_utils: #{file_utils.inspect}")
  @noids_command = kwargs.fetch(:noids_command) { default_noids_command }
  logger.debug("noids_command: #{noids_command.inspect}")
  @seconds_to_wait = kwargs.fetch(:seconds_to_wait) { SECONDS_TO_WAIT }
  logger.debug("seconds_to_wait: #{seconds_to_wait}")
end

Instance Attribute Details

#file_utilsObject (readonly)

Returns the value of attribute file_utils.



72
73
74
# File 'lib/noids_client/integration_test.rb', line 72

def file_utils
  @file_utils
end

#loggerObject (readonly)

Returns the value of attribute logger.



72
73
74
# File 'lib/noids_client/integration_test.rb', line 72

def logger
  @logger
end

#noids_commandObject (readonly)

Returns the value of attribute noids_command.



72
73
74
# File 'lib/noids_client/integration_test.rb', line 72

def noids_command
  @noids_command
end

#seconds_to_waitObject (readonly)

Returns the value of attribute seconds_to_wait.



72
73
74
# File 'lib/noids_client/integration_test.rb', line 72

def seconds_to_wait
  @seconds_to_wait
end

#storage_dirObject (readonly)

Returns the value of attribute storage_dir.



72
73
74
# File 'lib/noids_client/integration_test.rb', line 72

def storage_dir
  @storage_dir
end

Instance Method Details

#runObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/noids_client/integration_test.rb', line 92

def run
  clean_storage!
  process_id = Process.spawn("#{noids_command} --storage #{storage_dir}")
  Process.detach(process_id)
  logger.debug("Waiting #{seconds_to_wait} seconds for noids to start")
  sleep(seconds_to_wait)
  yield if block_given?
ensure
  stop_noids!(process_id: process_id)
end