Skip to content

Commit

Permalink
update rsmp gem to 0.31.0, update signal priority request tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emiltin committed Aug 23, 2024
1 parent 6049ec0 commit 477ac30
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source "https://rubygems.org"

gem 'rsmp', path: '/Users/emiltin/Documents/code/rsmp'
gem 'rsmp'
gem 'activesupport'

group :development do
Expand Down
16 changes: 6 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
PATH
remote: /Users/emiltin/Documents/code/rsmp
specs:
rsmp (0.30.0)
async (~> 2.12.0)
async-io (~> 1.43.0)
colorize (~> 1.1)
rsmp_schema (~> 0.7.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -55,6 +46,11 @@ GEM
mutex_m (0.2.0)
rake (13.2.1)
regexp_parser (2.9.2)
rsmp (0.31.0)
async (~> 2.12.0)
async-io (~> 1.43.0)
colorize (~> 1.1)
rsmp_schema (~> 0.7.0)
rsmp_schema (0.7.0)
json_schemer (~> 2.3.0)
thor (~> 1.3.1)
Expand Down Expand Up @@ -90,7 +86,7 @@ PLATFORMS
DEPENDENCIES
activesupport
rake
rsmp!
rsmp
rspec
yard

Expand Down
2 changes: 1 addition & 1 deletion spec/site/tlc/alarm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def verify_timestamp alarm, duration=1.minute
collect_task = task.async do
RSMP::AlarmCollector.new(site,
num: 1,
query: {
matcher: {
'aCId' => alarm_code_id,
'aSp' => /Acknowledge/i,
'ack' => /Acknowledged/i,
Expand Down
12 changes: 6 additions & 6 deletions spec/site/tlc/clock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@
status = status_list.keys.first.to_s

received = Time.new(
collector.query_result( {"sCI" => status, "n" => "year"} )['s'],
collector.query_result( {"sCI" => status, "n" => "month"} )['s'],
collector.query_result( {"sCI" => status, "n" => "day"} )['s'],
collector.query_result( {"sCI" => status, "n" => "hour"} )['s'],
collector.query_result( {"sCI" => status, "n" => "minute"} )['s'],
collector.query_result( {"sCI" => status, "n" => "second"} )['s'],
collector.matcher_result( {"sCI" => status, "n" => "year"} )['s'],
collector.matcher_result( {"sCI" => status, "n" => "month"} )['s'],
collector.matcher_result( {"sCI" => status, "n" => "day"} )['s'],
collector.matcher_result( {"sCI" => status, "n" => "hour"} )['s'],
collector.matcher_result( {"sCI" => status, "n" => "minute"} )['s'],
collector.matcher_result( {"sCI" => status, "n" => "second"} )['s'],
'UTC'
)

Expand Down
59 changes: 53 additions & 6 deletions spec/site/tlc/signal_priority_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@
# 6. When we cancel the request
# 7. Then the state should become 'completed'

it 'state reaches completed', sxl: '>=1.1' do |example|
it 'becomes completed when cancelled', sxl: '>=1.1' do |example|
Validator::Site.connected do |task,supervisor,site|
sequence = ['received','activated','completed']
timeout = Validator.get_config('timeouts','priority_completion')
component = Validator.get_config('main_component')
signal_group_id = Validator.get_config('components','signal_group').keys.first
Expand All @@ -77,27 +76,75 @@
)

prio.run do
log "Before: Send an unrelated signal priority"
#prio.request_unrelated
log "Before: Send unrelated signal priority request."
prio.request_unrelated

log "Send signal priority request, wait for reception."
prio.request

log "After: Send an unrelated signal priority request"
#prio.request_unrelated
log "After: Send unrelated signal priority request."
prio.request_unrelated

prio.expect :received
log "Signal priority request was received, wait for activation."

prio.expect :activated
log "Signal priority request was activated, now cancel it and wait for completion."


prio.cancel
prio.expect :completed
log "Signal priority request was completed."
end
end
end

# Validate that a signal priority times out if not cancelled.
#
# 1. Given the site is connected
# 2. And we subscribe to signal priority status
# 3. When we send a signal priority request
# 4. Then the request state should become 'received'
# 5. Then the request state should become 'activated'
# 6. When we do not cancel the request
# 7. Then the state should become 'stale'

it 'becomes stale if not cancelled', sxl: '>=1.1' do |example|
Validator::Site.connected do |task,supervisor,site|
timeout = Validator.get_config('timeouts','priority_completion')
component = Validator.get_config('main_component')
signal_group_id = Validator.get_config('components','signal_group').keys.first
prio = Validator::StatusHelpers::SignalPriorityRequestHelper.new(
site,
component: component,
signal_group_id: signal_group_id,
timeout: timeout,
task: task
)

prio.run do
log "Before: Send unrelated signal priority request."
prio.request_unrelated

log "Send signal priority request, wait for reception."
prio.request

log "After: Send unrelated signal priority request."
prio.request_unrelated

prio.expect :received
log "Signal priority request was received, wait for activation."

prio.expect :activated
log "Signal priority request was activated, wait for it to become stale."


# don't cancel request, it should then become stale by itself
prio.expect :stale
log "Signal priority request became stale."
end
end
end

end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require_relative 'support/formatters/brief.rb'
require_relative 'support/formatters/details.rb'
require_relative 'support/formatters/list.rb'
require_relative 'support/formatters/steps.rb'

include RSpec
include Validator::Log
Expand Down
12 changes: 6 additions & 6 deletions spec/support/command_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def set_functional_position status, timeout_minutes:0
securityCode: Validator.get_config('secrets','security_codes',2),
status: status,
timeout: timeout_minutes,
intersection: 0
intersection: 0,
}
send_command_and_confirm @task, command_list, "Switch to functional position #{status}"
end
Expand Down Expand Up @@ -216,7 +216,7 @@ def get_dynamic_bands plan, band
timeout: Validator.get_config('timeouts','status_update', default: 0)
}
collector = result[:collector]
collector.queries.first.got['s'].split(',').each do |item|
collector.matchers.first.got['s'].split(',').each do |item|
some_plan, some_band, value = *item.split('-')
return value.to_i if some_plan.to_i == plan.to_i && some_band.to_i == band.to_i
end
Expand Down Expand Up @@ -368,7 +368,7 @@ def with_alarm_activated task, site, alarm_code_id, initial_deactivation: true
collect_task = task.async do # run the collector in an async task
collector = RSMP::AlarmCollector.new( site,
num: 1,
query: {
matcher: {
'cId' => component_id,
'aCId' => alarm_code_id,
'aSp' => alarm_specialization,
Expand All @@ -386,7 +386,7 @@ def with_alarm_activated task, site, alarm_code_id, initial_deactivation: true
collect_task = task.async do # run the collector in an async task
collector = RSMP::AlarmCollector.new( site,
num: 1,
query: {
matcher: {
'cId' => component_id,
'aCId' => alarm_code_id,
'aSp' => /Issue/i,
Expand Down Expand Up @@ -575,7 +575,7 @@ def suspend_alarm site, task, cId:, aCId:, collect:
RSMP::AlarmCollector.new(site,
m_id: suspend.m_id,
num: 1,
query: {
matcher: {
'cId' => cId,
'aCI' => aCId,
'aSp' => 'Suspend',
Expand Down Expand Up @@ -603,7 +603,7 @@ def resume_alarm site, task, cId:, aCId:, collect:
RSMP::AlarmCollector.new(site,
m_id: resume.m_id,
num: 1,
query: {
matcher: {
'cId' => cId,
'aCI'=>aCId,
'aSp'=>'Suspend',
Expand Down
12 changes: 6 additions & 6 deletions spec/support/signal_priority_request_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Validator::StatusHelpers

# Match a specific status response or update
class S0033Query < RSMP::StatusQuery
class S0033Matcher < RSMP::StatusMatcher

attr_accessor :state
def initialize want, request_id:, state: nil
Expand All @@ -11,7 +11,7 @@ def initialize want, request_id:, state: nil
@latest_state = nil
end

# Match a status value against a query
# Match a status value against a matcher
def match? item
super_matched = super(item)
if super_matched == true
Expand All @@ -23,7 +23,7 @@ def match? item
false
end
else
super_match
super_matched
end
end

Expand Down Expand Up @@ -55,7 +55,7 @@ def initialize site, component:, signal_group_id:, timeout:, task:
@component = component
@signal_group_id = signal_group_id
@request_id = SecureRandom.uuid()[0..3]
@query = S0033Query.new({"cCI"=>"S0033", "q"=>"recent"}, request_id: @request_id)
@matcher = S0033Matcher.new({"cCI"=>"S0033", "q"=>"recent"}, request_id: @request_id)
@subscribe_list = [{'sCI'=>'S0033','n'=>'status','uRt'=>'0'}]
@subscribe_list.map! { |item| item.merge!('sOc' => true) } if use_sOc?(@site)
@unsubscribe_list = [{'sCI'=>'S0033','n'=>'status'}]
Expand Down Expand Up @@ -111,7 +111,7 @@ def cancel
end

def expect state
@query.state = state
@matcher.state = state
message = wait_for_message timeout: @timeout
rescue RSMP::TimeoutError
raise RSMP::TimeoutError.new("Priority request did not reach state #{state} within #{@timeout}s")
Expand All @@ -120,7 +120,7 @@ def expect state
private

def accept_message? message
super && get_items(message).any? {|item| @query.match?(item) }
super && get_items(message).any? {|item| @matcher.match?(item) }
end

def start
Expand Down

0 comments on commit 477ac30

Please sign in to comment.