Skip to content

Commit

Permalink
prio helper
Browse files Browse the repository at this point in the history
  • Loading branch information
emiltin committed Aug 21, 2024
1 parent 99a3422 commit 3e311aa
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 264 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'
gem 'rsmp', path: '/Users/emiltin/Documents/code/rsmp'
gem 'activesupport'

group :development do
Expand Down
26 changes: 15 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
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 All @@ -11,18 +20,18 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
async (2.12.0)
async (2.12.1)
console (~> 1.25, >= 1.25.2)
fiber-annotation
io-event (~> 1.6)
io-event (~> 1.6, >= 1.6.5)
async-io (1.43.2)
async
base64 (0.2.0)
bigdecimal (3.1.8)
colorize (1.1.0)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
console (1.25.2)
console (1.27.0)
fiber-annotation
fiber-local (~> 1.1)
json
Expand All @@ -31,11 +40,11 @@ GEM
fiber-annotation (0.2.0)
fiber-local (1.1.0)
fiber-storage
fiber-storage (0.1.2)
fiber-storage (1.0.0)
hana (1.3.7)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
io-event (1.6.4)
io-event (1.6.5)
json (2.7.2)
json_schemer (2.3.0)
bigdecimal
Expand All @@ -46,11 +55,6 @@ GEM
mutex_m (0.2.0)
rake (13.2.1)
regexp_parser (2.9.2)
rsmp (0.29.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 @@ -86,7 +90,7 @@ PLATFORMS
DEPENDENCIES
activesupport
rake
rsmp
rsmp!
rspec
yard

Expand Down
3 changes: 3 additions & 0 deletions config/gem_tlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ alarms:
restrict_testing:
sxl_version: 1.2.1
core_version: 3.2.2
log:
watchdogs: false
acknowledgements: false
116 changes: 30 additions & 86 deletions spec/site/tlc/signal_priority_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
end
end

# Validate that a signal priority becomes completed when we cancel it.
# Validate that a signal priority completes when we cancel it.
#
# 1. Given the site is connected
# 2. And we subscribe to signal priority status
Expand All @@ -64,93 +64,37 @@

it 'state reaches completed', sxl: '>=1.1' do |example|
Validator::Site.connected do |task,supervisor,site|

sequence = ['received','activated','completed']
timeout = Validator.get_config('timeouts','priority_completion'),

prio = Validator::StatusHelpers::PriorityHelper.new(site: site, component: component)

prio_options = {
signalGroupId: signal_group,
level: 7,
eta: 2,
vehicleType: 'car'
}

prio.validate_sequence do |state|
case state
when nil:
log "Send an unrelated signal priority request before"
prio.request_unrelated prio_options
log "Send signal priority request, wait for reception."
prio.request prio_options
log "Send an unrelated signal priority request after"
prio.request_unrelated prio_options
prio.next 'received', timeout: timeout

when 'received':
log "Signal priority request was received, wait for activation."
prio.next 'activated', timeout: timeout

when 'acticated':
log "Signal priority request was activated, now cancel it and wait for completion."
prio.cancel
prio.next 'completed', timeout: timeout

when 'completed':
log "Signal priority request was completed."
prio.done
end
end
end

# Validate that a signal priority became stale if we do not cancel it.
#
# 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. And the request state should become 'activated'
# 7. Then the state should become 'stale'

it 'state becomes stale', sxl: '>=1.1' do |example|
Validator::Site.connected do |task,supervisor,site|
sequence = ['received','activated','completed']
timeout = Validator.get_config('timeouts','priority_completion'),
timeout = Validator.get_config('timeouts','priority_completion')
component = Validator.get_config('main_component')
signal_group = Validator.get_config('components','signal_group').keys.first

prio = Validator::StatusHelpers::PriorityHelper.new(site: site, component: component)

prio_options = {
signalGroupId: signal_group,
level: 7,
eta: 2,
vehicleType: 'car'
}

prio.validate_sequence do |state|
case state
when nil:
log "Send an unrelated signal priority request before"
prio.request_unrelated prio_options
log "Send signal priority request, wait for reception."
prio.request prio_options
log "Send an unrelated signal priority request after"
prio.request_unrelated prio_options
prio.next 'received', timeout: timeout

when 'received':
log "Signal priority request was received, wait for activation."
prio.next 'activated', timeout: timeout

when 'acticated':
log "Signal priority request was activated, wait for it to become stale."
prio.next 'completed', timeout: timeout

when 'stale':
log "Signal priority request became stale."
prio.done
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 an unrelated signal priority"
#prio.request_unrelated

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

log "After: Send an 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
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
require_relative 'support/test_supervisor'
require_relative 'support/command_helpers'
require_relative 'support/status_helpers'
require_relative 'support/sequence_helper'
require_relative 'support/signal_group_sequence_helper'
require_relative 'support/signal_priority_request_helper'
require_relative 'support/log_helpers'
require_relative 'support/handshake_helper'
require_relative 'support/formatters/report_stream.rb'
Expand Down
2 changes: 1 addition & 1 deletion spec/support/command_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def verify_startup_sequence &block
component = Validator.get_config('main_component')
timeout = Validator.get_config('timeouts','startup_sequence')
collector = RSMP::StatusCollector.new @site, status_list, timeout: timeout
sequencer = Validator::StatusHelpers::SequenceHelper.new Validator.get_config('startup_sequence')
sequencer = Validator::StatusHelpers::SignalGroupSequenceHelper.new Validator.get_config('startup_sequence')
states = nil

collector_task = @task.async do
Expand Down
Loading

0 comments on commit 3e311aa

Please sign in to comment.