Skip to content

Commit

Permalink
update test for invalid status requests
Browse files Browse the repository at this point in the history
  • Loading branch information
emiltin committed Jul 11, 2023
1 parent c4dbe97 commit 515f15e
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 35 deletions.
1 change: 1 addition & 0 deletions spec/site/tlc/invalid_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
result = site.send_command '', command_list,
collect: { timeout: Validator.config['timeouts']['command_response'] },
validate: false # disable validation of outgoing message
)
collector = result[:collector]
expect(collector).to be_an(RSMP::Collector)
expect(collector.status).to eq(:ok)
Expand Down
86 changes: 86 additions & 0 deletions spec/site/tlc/invalid_status_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
RSpec.describe 'Site::Traffic Light Controller' do
include Validator::StatusHelpers

context 'receiving a status request with an unknown component id' do

# Verify that site reponds with NotAck when receive a status request
# with an unknown component id
#
# 1. Given the site is connected
# 2. When we send a status request with an unknown component id
# 3. Then the site should return a status response with q=undefined

it 'return a command response with age=undefined' do |example|
Validator::Site.connected do |task,supervisor,site|
log "Sending M0001 with bad component id"
status_list = convert_status_list( S0001:[:signalgroupstatus] )
result = site.request_status(
'bad',
status_list,
collect: { timeout: Validator.config['timeouts']['status_response'] },
validate: false
)
collector = result[:collector]
expect(collector).to be_an(RSMP::Collector)
expect(collector.status).to eq(:ok)
response = collector.messages.first
expect(response).to be_an(RSMP::StatusResponse)
sS = response.attributes['sS']
expect(sS).to be_an(Array)
sS.each do |s|
q = s['q']
expect(q).to eq('undefined'), "expected sS q attribute to be 'undefined', got #{s.inspect}"
end
end
end
end


context 'receiving a status request for an unknown status' do
# Verify that site returns NotAck when receiving
# a request for an unknown status
#
# 1. Given the site is connected
# 2. When we send a non-existing S000 status request
# 3. Then the site should return NotAck
it 'returns NotAck' do |example|
Validator::Site.connected do |task,supervisor,site|
log "Requesting non-existing status S0000"
status_list = convert_status_list( S0000:[:status] )
result = site.request_status(
Validator.config['main_component'], status_list,
collect: { timeout: Validator.config['timeouts']['status_response'] },
validate: false
)
collector = result[:collector]
expect(collector).to be_an(RSMP::Collector)
expect(collector.status).to eq(:cancelled)
expect(collector.error).to be_an(RSMP::MessageRejected)
end
end
end

context 'receiving a status request with an invalid status name' do
# Verify that site returns NotAck when receiving
# a request for an unknown status
#
# 1. Given the site is connected
# 2. When we send an S0001 request with the stauts name 'bad'
# 3. Then the site should return NotAck
it 'returns NotAck' do |example|
Validator::Site.connected do |task,supervisor,site|
log "Requesting S0001 with non-existing status name"
status_list = convert_status_list( S0001:[:bad] )
result = site.request_status(
Validator.config['main_component'], status_list,
collect: { timeout: Validator.config['timeouts']['status_response'] },
validate: false
)
collector = result[:collector]
expect(collector).to be_an(RSMP::Collector)
expect(collector.status).to eq(:cancelled)
expect(collector.error).to be_an(RSMP::MessageRejected)
end
end
end
end
35 changes: 0 additions & 35 deletions spec/site/tlc/unknown_status_spec.rb

This file was deleted.

0 comments on commit 515f15e

Please sign in to comment.