Class: RSMP::Validator::AutoNode

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/rsmp/validator/auto_node.rb

Overview

Base class for automatically starting a local RSMP node (site or supervisor) when testing the validator or RSMP gem itself.

Direct Known Subclasses

AutoSite, AutoSupervisor

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

#log

Constructor Details

#initializeAutoNode

Returns a new instance of AutoNode.



12
13
14
15
# File 'lib/rsmp/validator/auto_node.rb', line 12

def initialize
  @node = nil
  @task = nil
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



10
11
12
# File 'lib/rsmp/validator/auto_node.rb', line 10

def node
  @node
end

#taskObject (readonly)

Returns the value of attribute task.



10
11
12
# File 'lib/rsmp/validator/auto_node.rb', line 10

def task
  @task
end

Instance Method Details

#running?Boolean

Check if the auto node is running

Returns:

  • (Boolean)


47
48
49
# File 'lib/rsmp/validator/auto_node.rb', line 47

def running?
  @node && @task
end

#startObject

Start the auto node inside the async reactor



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rsmp/validator/auto_node.rb', line 18

def start
  return if @node

  @node = build_node

  @task = Async do |task|
    task.annotate "auto_#{node_type}"
    log("Starting auto #{node_type}")
    @node.start
  rescue Async::TimeoutError
    raise RSMP::TimeoutError, "Timeout while starting auto #{node_type}"
  end
end

#stopObject

Stop the auto node



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rsmp/validator/auto_node.rb', line 33

def stop
  if @node
    log("Stopping auto #{node_type}")
    @node.ignore_errors RSMP::DisconnectError do
      @node.stop
    end
  end
  @task&.stop
ensure
  @task = nil
  @node = nil
end