Class: Validator::AutoNode

Inherits:
Object
  • Object
show all
Defined in:
spec/support/auto_node.rb

Direct Known Subclasses

AutoSite, AutoSupervisor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAutoNode

Returns a new instance of AutoNode.



13
14
15
16
# File 'spec/support/auto_node.rb', line 13

def initialize
  @node = nil
  @task = nil
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



11
12
13
# File 'spec/support/auto_node.rb', line 11

def node
  @node
end

#taskObject (readonly)

Returns the value of attribute task.



11
12
13
# File 'spec/support/auto_node.rb', line 11

def task
  @task
end

Instance Method Details

#running?Boolean

Check if the auto node is running

Returns:

  • (Boolean)


54
55
56
# File 'spec/support/auto_node.rb', line 54

def running?
  @node && @task
end

#startObject

Start the auto node inside the async reactor This method should be called from within the reactor context



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'spec/support/auto_node.rb', line 20

def start
  return if @node

  Validator.log "Starting auto #{node_type}", level: :info
  
  @node = build_node
  
  # Run the node in a separate async task within the same reactor
  @task = Async do |task|
    task.annotate "auto_#{node_type}"
    begin
      @node.start  # This will keep running until stopped
    rescue StandardError => e
      Validator.log "Auto #{node_type} error: #{e.class}: #{e.message}", level: :error
      raise
    end
  end
end

#stopObject

Stop the auto node



40
41
42
43
44
45
46
47
48
49
50
51
# File 'spec/support/auto_node.rb', line 40

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