Class: Validator::Site

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

Overview

The block will pass an RSMP::SiteProxy object, which can be used to communicate with the site. For example you can send commands, wait for responses, subscribe to statuses, etc.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Testee

#config, #connected, #disconnected, #isolated, #reconnected, sentinel_errors, #stop

Class Attribute Details

.testeeObject

Returns the value of attribute testee.



43
44
45
# File 'spec/support/test_site.rb', line 43

def testee
  @testee
end

Class Method Details

.connected(options = {}, &block) ⇒ Object



45
46
47
# File 'spec/support/test_site.rb', line 45

def connected options={}, &block
  testee.connected options, &block
end

.disconnected(&block) ⇒ Object



53
54
55
# File 'spec/support/test_site.rb', line 53

def disconnected &block
  testee.disconnected &block
end

.isolated(options = {}, &block) ⇒ Object



57
58
59
# File 'spec/support/test_site.rb', line 57

def isolated options={}, &block
  testee.isolated options, &block
end

.reconnected(options = {}, &block) ⇒ Object



49
50
51
# File 'spec/support/test_site.rb', line 49

def reconnected options={}, &block
  testee.reconnected options, &block
end

.stopObject



61
62
63
# File 'spec/support/test_site.rb', line 61

def stop
  testee.stop
end

Instance Method Details

#build_node(options) ⇒ Object

build local supervisor



92
93
94
95
96
97
98
# File 'spec/support/test_site.rb', line 92

def build_node options
  RSMP::Supervisor.new(
    supervisor_settings: @supervisor_config.deep_merge(options),
    logger: Validator.logger,
    collect: options['collect']
  )
end

#parse_configObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'spec/support/test_site.rb', line 66

def parse_config
  # build rsmp supervisor config by
  # picking elements from the config
  want = ['sxl','intervals','timeouts','components','rsmp_versions','skip_validation']
  guest_settings = config.select { |key| want.include? key }
  @supervisor_config = {
    'port' => config['port'],
    'max_sites' => 1,
    'guest' => guest_settings
  }
  [
    'connect',
    'ready',
    'status_response',
    'status_update',
    'subscribe',
    'command',
    'command_response',
    'alarm',
    'disconnect',
  ].each do |key|
    raise "config 'timeouts/#{key}' is missing" unless config['timeouts'][key]
  end
end

#wait_for_connectionObject

Wait for an rsmp site to connect to the supervisor



101
102
103
104
105
106
107
108
# File 'spec/support/test_site.rb', line 101

def wait_for_connection
  @proxy = @node.proxies.first
  return if @proxy
  Validator::Log.log "Waiting for site to connect"
  @proxy = @node.wait_for_site(:any, timeout:config['timeouts']['connect'])
rescue RSMP::TimeoutError
  raise RSMP::ConnectionError.new "Site did not connect within #{config['timeouts']['connect']}s"
end

#wait_for_handshakeObject

Wait for an the rsmp handshake to complete



111
112
113
114
115
116
# File 'spec/support/test_site.rb', line 111

def wait_for_handshake
  return if @proxy.ready?
  Validator::Log.log "Waiting for handskake to complete"
  @proxy.wait_for_state :ready, timeout:config['timeouts']['ready']
  Validator::Log.log "Ready"
end