class NoidsClient::IntegrationTest::NoidServerRunner
A utility class to help running a NOIDs server within the context
@example
require 'noids_client/integration_test' NoidsClient::IntegrationTest::NoidServerRunner.new do # thing that requires a noids server end
Constants
- SECONDS_TO_WAIT
Attributes
file_utils[R]
logger[R]
noids_command[R]
seconds_to_wait[R]
storage_dir[R]
Public Class Methods
new(**kwargs)
click to toggle source
@param kwargs [Hash] the configuration options for the NoidsServer. Note,
you shouldn't need to pass parameters if you follow the noids documentation
@option logger [#debug, info] @option storage_dir
[String] @option file_utils
[#mkdir_p, rm_rf] the object that will manage cleaning
the storage_dir
@option noids_command
[String] the fully expanded to the noids command @option seconds_to_wait
[Integer] how long to wait for the noids server to
fully boot
# 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
Public Instance Methods
run() { || ... }
click to toggle source
# 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
Private Instance Methods
clean_storage!()
click to toggle source
# File lib/noids_client/integration_test.rb, line 105 def clean_storage! logger.info("Cleaning noids: #{storage_dir}") file_utils.rm_rf(storage_dir) file_utils.mkdir_p(storage_dir) end
default_file_utils()
click to toggle source
# File lib/noids_client/integration_test.rb, line 84 def default_file_utils require 'fileutils' FileUtils end
default_noids_command()
click to toggle source
# File lib/noids_client/integration_test.rb, line 80 def default_noids_command File.join(ENV.fetch("GOPATH"), "bin/noids") end
default_storage_dir()
click to toggle source
# File lib/noids_client/integration_test.rb, line 76 def default_storage_dir File.join(ENV.fetch("HOME"), "noids_pool") end
start_noids!()
click to toggle source
# File lib/noids_client/integration_test.rb, line 111 def start_noids! # `$GOPATH/bin/noids --storage ~/noids_pool` logger.info("Starting noids server…") IO.popen("#{noids_command} --storage #{storage_dir}", err: [:child, :out]) end
stop_noids!(process_id:)
click to toggle source
# File lib/noids_client/integration_test.rb, line 117 def stop_noids!(process_id:) logger.info("Shutting down server…") Process.kill(:SIGINT, process_id) return true end