Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use helpers for suspending/resuming alarm, fix regex for Suspend #362

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 13 additions & 50 deletions spec/site/tlc/alarm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,59 +142,22 @@ def verify_timestamp alarm, duration=1.minute
skip "alarm #{alarm_code_id} is not configured" unless action
component_id = action['component']
skip "alarm #{alarm_code_id} has no component configured" unless component_id
# first resume to make sure something happens when we suspend
resume = RSMP::AlarmResume.new(
'cId' => component_id,
'aCId' => alarm_code_id
)
site.send_message resume

# now suspend the alarm while collecting responses
suspend = RSMP::AlarmSuspend.new(
'mId' => RSMP::Message.make_m_id, # generate a message id, that can be used to listen for responses
'cId' => component_id,
'aCId' => alarm_code_id
)
collect_task = task.async do
RSMP::AlarmCollector.new(site,
m_id: suspend.m_id,
num: 1,
query: {
'cId' => component_id,
'aCI' => alarm_code_id,
'aSp' => 'Suspend',
'sS' => /Suspended/i
},
timeout: Validator.get_config('timeouts','alarm')
).collect!
end

begin
site.send_message suspend
messages = collect_task.wait
expect(messages).to be_an(Array)
message = messages.first
expect(message).to be_a(RSMP::AlarmSuspended)
rescue
site.send_message resume # clean up by resuming alarm
raise
end
# first resume alarm to make sure something happens when we suspend
resume_alarm site, task, cId: component_id, aCId: alarm_code_id, collect: false

# clean up by resuming alarm
resume.attributes['mId'] = RSMP::Message.make_m_id # generate a message id, that can be used to listen for responses
collect_task = task.async do
RSMP::AlarmCollector.new(site,
m_id: resume.m_id,
num: 1,
query: {'aCI'=>alarm_code_id,'aSp'=>'Suspend','sS'=>'notSuspended'},
timeout: Validator.get_config('timeouts','alarm')
).collect!
begin
# suspend alarm
request, response = suspend_alarm site, task, cId: component_id, aCId: alarm_code_id, collect: true
expect(response).to be_a(RSMP::AlarmSuspended)

# resume alarm
request, response = resume_alarm site, task, cId: component_id, aCId: alarm_code_id, collect: true
expect(response).to be_a(RSMP::AlarmResumed)
ensure
# always end with resuming alarm
resume_alarm site, task, cId: component_id, aCId: alarm_code_id, collect: false
end
site.send_message resume
messages = collect_task.wait
expect(messages).to be_an(Array)
message = messages.first
expect(message).to be_a(RSMP::AlarmResumed)
end
end
end
Expand Down
56 changes: 56 additions & 0 deletions spec/support/command_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,62 @@ def switch_input indx
)
end

def suspend_alarm site, task, cId:, aCId:, collect:
suspend = RSMP::AlarmSuspend.new(
'mId' => RSMP::Message.make_m_id, # generate a message id, that can be used to listen for responses
'cId' => cId,
'aCId' => aCId
)
if collect
collect_task = task.async do
RSMP::AlarmCollector.new(site,
m_id: suspend.m_id,
num: 1,
query: {
'cId' => cId,
'aCI' => aCId,
'aSp' => 'Suspend',
'sS' => /^Suspended/i
},
timeout: Validator.config['timeouts']['alarm']
).collect!
end
site.send_message suspend
return suspend, collect_task.wait.first
else
site.send_message suspend
suspend
end
end

def resume_alarm site, task, cId:, aCId:, collect:
resume = RSMP::AlarmResume.new(
'mId' => RSMP::Message.make_m_id, # generate a message id, that can be used to listen for responses
'cId' => cId,
'aCId' => aCId
)
if collect
collect_task = task.async do
RSMP::AlarmCollector.new(site,
m_id: resume.m_id,
num: 1,
query: {
'cId' => cId,
'aCI'=>aCId,
'aSp'=>'Suspend',
'sS'=>/^notSuspended/i
},
timeout: Validator.config['timeouts']['alarm']
).collect!
end
site.send_message resume
return resume, collect_task.wait.first
else
site.send_message resume
resume
end
end

def prepare task, site
@task = task
@site = site
Expand Down