Skip to content

Commit

Permalink
update rsmp gem, use with_watchdog_disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
emiltin committed Dec 13, 2023
1 parent 1381e9d commit 67373e0
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 109 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ GEM
async
colorize (0.8.1)
concurrent-ruby (1.2.2)
console (1.23.2)
console (1.23.3)
fiber-annotation
fiber-local
diff-lcs (1.5.0)
Expand All @@ -25,14 +25,14 @@ GEM
i18n (1.14.1)
concurrent-ruby (~> 1.0)
io-event (1.3.3)
json_schemer (2.1.0)
json_schemer (2.1.1)
hana (~> 1.3)
regexp_parser (~> 2.0)
simpleidn (~> 0.2)
minitest (5.20.0)
rake (13.0.6)
regexp_parser (2.8.2)
rsmp (0.25.3)
regexp_parser (2.8.3)
rsmp (0.26.0)
async (~> 2.6.4)
async-io (~> 1.36.0)
colorize (~> 0.8.1)
Expand Down
6 changes: 4 additions & 2 deletions spec/site/core/disconnect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def site_proxy.acknowledge original
it 'is not closed if watchdogs are not received', sxl: '>=1.0.7', slow: true do |example|
Validator::Site.isolated do |task,supervisor,site|
timeout = Validator.config['timeouts']['disconnect']

wait_task = task.async do
site.wait_for_state :disconnected, timeout: timeout
raise RSMP::DisconnectError
Expand All @@ -46,8 +47,9 @@ def site_proxy.acknowledge original
end

log "Stop sending watchdogs, site should not disconnect"
stop_sending_watchdogs(site)
wait_task.wait
site.with_watchdog_disabled do
wait_task.wait
end
end
end
end
Expand Down
213 changes: 110 additions & 103 deletions spec/site/tlc/clock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,40 +54,41 @@
it 'is used for S0096 status response', sxl: '>=1.0.7' do |example|
Validator::Site.connected do |task,supervisor,site|
prepare task, site
stop_sending_watchdogs(site) # avoid time synchronization by watchdogs
with_clock_set CLOCK do
status_list = { S0096: [
:year,
:month,
:day,
:hour,
:minute,
:second,
] }
result = site.request_status Validator.config['main_component'], convert_status_list(status_list), collect!: {
timeout: Validator.config['timeouts']['status_update']
}
collector = result[:collector]
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'],
'UTC'
)

max_diff =
Validator.config['timeouts']['command_response'] +
Validator.config['timeouts']['status_response']

diff = received - CLOCK
diff = diff.round
expect(diff.abs).to be <= max_diff,
"Clock reported by S0096 is off by #{diff}s, should be within #{max_diff}s"
site.with_watchdog_disabled do # avoid time synchronization by disabling watchdogs
with_clock_set CLOCK do
status_list = { S0096: [
:year,
:month,
:day,
:hour,
:minute,
:second,
] }
result = site.request_status Validator.config['main_component'], convert_status_list(status_list), collect!: {
timeout: Validator.config['timeouts']['status_update']
}
collector = result[:collector]
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'],
'UTC'
)

max_diff =
Validator.config['timeouts']['command_response'] +
Validator.config['timeouts']['status_response']

diff = received - CLOCK
diff = diff.round
expect(diff.abs).to be <= max_diff,
"Clock reported by S0096 is off by #{diff}s, should be within #{max_diff}s"
end
end
end
end
Expand All @@ -102,29 +103,30 @@
it 'is used for S0096 response timestamp', sxl: '>=1.0.7' do |example|
Validator::Site.connected do |task,supervisor,site|
prepare task, site
stop_sending_watchdogs(site) # avoid time synchronization by watchdogs
with_clock_set CLOCK do
status_list = { S0096: [
:year,
:month,
:day,
:hour,
:minute,
:second,
] }

result = site.request_status Validator.config['main_component'],
convert_status_list(status_list),
collect!: {
timeout: Validator.config['timeouts']['status_response']
}
collector = result[:collector]
site.with_watchdog_disabled do # avoid time synchronization by disabling watchdogs
with_clock_set CLOCK do
status_list = { S0096: [
:year,
:month,
:day,
:hour,
:minute,
:second,
] }

max_diff = Validator.config['timeouts']['command_response'] + Validator.config['timeouts']['status_response']
diff = Time.parse(collector.messages.first.attributes['sTs']) - CLOCK
diff = diff.round
expect(diff.abs).to be <= max_diff,
"Timestamp of S0096 is off by #{diff}s, should be within #{max_diff}s"
result = site.request_status Validator.config['main_component'],
convert_status_list(status_list),
collect!: {
timeout: Validator.config['timeouts']['status_response']
}
collector = result[:collector]

max_diff = Validator.config['timeouts']['command_response'] + Validator.config['timeouts']['status_response']
diff = Time.parse(collector.messages.first.attributes['sTs']) - CLOCK
diff = diff.round
expect(diff.abs).to be <= max_diff,
"Timestamp of S0096 is off by #{diff}s, should be within #{max_diff}s"
end
end
end
end
Expand All @@ -140,17 +142,18 @@
it 'is used for aggregated status timestamp', core: '>=3.1.5', sxl: '>=1.0.7' do |example|
Validator::Site.connected do |task,supervisor,site|
prepare task, site
stop_sending_watchdogs(site) # avoid time synchronization by watchdogs
with_clock_set CLOCK do
result = site.request_aggregated_status Validator.config['main_component'], collect!: {
timeout: Validator.config['timeouts']['status_response']
}
collector = result[:collector]
max_diff = Validator.config['timeouts']['command_response'] + Validator.config['timeouts']['status_response']
diff = Time.parse(collector.messages.first.attributes['aSTS']) - CLOCK
diff = diff.round
expect(diff.abs).to be <= max_diff,
"Timestamp of aggregated status is off by #{diff}s, should be within #{max_diff}s"
site.with_watchdog_disabled do # avoid time synchronization by disabling watchdogs
with_clock_set CLOCK do
result = site.request_aggregated_status Validator.config['main_component'], collect!: {
timeout: Validator.config['timeouts']['status_response']
}
collector = result[:collector]
max_diff = Validator.config['timeouts']['command_response'] + Validator.config['timeouts']['status_response']
diff = Time.parse(collector.messages.first.attributes['aSTS']) - CLOCK
diff = diff.round
expect(diff.abs).to be <= max_diff,
"Timestamp of aggregated status is off by #{diff}s, should be within #{max_diff}s"
end
end
end
end
Expand All @@ -165,15 +168,16 @@
it 'is used for M0001 response timestamp', sxl: '>=1.0.7' do |example|
Validator::Site.connected do |task,supervisor,site|
prepare task, site
stop_sending_watchdogs(site) # avoid time synchronization by watchdogs
with_clock_set CLOCK do
result = set_functional_position 'NormalControl'
collector = result[:collector]
max_diff = Validator.config['timeouts']['command_response'] * 2
diff = Time.parse(collector.messages.first.attributes['cTS']) - CLOCK
diff = diff.round
expect(diff.abs).to be <= max_diff,
"Timestamp of command response is off by #{diff}s, should be within #{max_diff}s"
site.with_watchdog_disabled do # avoid time synchronization by disabling watchdogs
with_clock_set CLOCK do
result = set_functional_position 'NormalControl'
collector = result[:collector]
max_diff = Validator.config['timeouts']['command_response'] * 2
diff = Time.parse(collector.messages.first.attributes['cTS']) - CLOCK
diff = diff.round
expect(diff.abs).to be <= max_diff,
"Timestamp of command response is off by #{diff}s, should be within #{max_diff}s"
end
end
end
end
Expand All @@ -188,15 +192,16 @@
it 'is used for M0104 response timestamp', sxl: '>=1.0.7' do |example|
Validator::Site.connected do |task,supervisor,site|
prepare task, site
stop_sending_watchdogs(site) # avoid time synchronization by watchdogs
with_clock_set CLOCK do
result = set_functional_position 'NormalControl'
collector = result[:collector]
max_diff = Validator.config['timeouts']['command_response']
diff = Time.parse(collector.messages.first.attributes['cTS']) - CLOCK
diff = diff.round
expect(diff.abs).to be <= max_diff,
"Timestamp of command response is off by #{diff}s, should be within #{max_diff}s"
site.with_watchdog_disabled do # avoid time synchronization by disabling watchdogs
with_clock_set CLOCK do
result = set_functional_position 'NormalControl'
collector = result[:collector]
max_diff = Validator.config['timeouts']['command_response']
diff = Time.parse(collector.messages.first.attributes['cTS']) - CLOCK
diff = diff.round
expect(diff.abs).to be <= max_diff,
"Timestamp of command response is off by #{diff}s, should be within #{max_diff}s"
end
end
end
end
Expand All @@ -215,14 +220,15 @@
it 'is used for alarm timestamp', :programming, sxl: '>=1.0.7' do |example|
Validator::Site.connected do |task,supervisor,site|
prepare task, site
stop_sending_watchdogs(site) # avoid time synchronization by watchdogs
with_clock_set CLOCK do # set clock
with_alarm_activated(task, site, 'A0302') do |alarm| # raise alarm, by activating input
alarm_time = Time.parse( alarm.attributes["aTs"] )
max_diff = Validator.config['timeouts']['command_response'] + Validator.config['timeouts']['status_response']
diff = alarm_time - CLOCK
expect(diff.round.abs).to be <= max_diff,
"Timestamp of alarm is off by #{diff}s, should be within #{max_diff}s"
site.with_watchdog_disabled do # avoid time synchronization by disabling watchdogs
with_clock_set CLOCK do # set clock
with_alarm_activated(task, site, 'A0302') do |alarm| # raise alarm, by activating input
alarm_time = Time.parse( alarm.attributes["aTs"] )
max_diff = Validator.config['timeouts']['command_response'] + Validator.config['timeouts']['status_response']
diff = alarm_time - CLOCK
expect(diff.round.abs).to be <= max_diff,
"Timestamp of alarm is off by #{diff}s, should be within #{max_diff}s"
end
end
end
end
Expand All @@ -238,16 +244,17 @@
it 'is used for watchdog timestamp', sxl: '>=1.0.7' do |example|
Validator::Site.connected do |task,supervisor,site|
prepare task, site
stop_sending_watchdogs(site) # avoid time synchronization by watchdogs
with_clock_set CLOCK do
log "Checking watchdog timestamp"
collector = RSMP::Collector.new site, task:task, type: "Watchdog", num: 1, timeout: Validator.config['timeouts']['watchdog']
collector.collect!
max_diff = Validator.config['timeouts']['command_response'] + Validator.config['timeouts']['status_response']
diff = Time.parse(collector.messages.first.attributes['wTs']) - CLOCK
diff = diff.round
expect(diff.abs).to be <= max_diff,
"Timestamp of watchdog is off by #{diff}s, should be within #{max_diff}s"
site.with_watchdog_disabled do # avoid time synchronization by disabling watchdogs
with_clock_set CLOCK do
log "Checking watchdog timestamp"
collector = RSMP::Collector.new site, task:task, type: "Watchdog", num: 1, timeout: Validator.config['timeouts']['watchdog']
collector.collect!
max_diff = Validator.config['timeouts']['command_response'] + Validator.config['timeouts']['status_response']
diff = Time.parse(collector.messages.first.attributes['wTs']) - CLOCK
diff = diff.round
expect(diff.abs).to be <= max_diff,
"Timestamp of watchdog is off by #{diff}s, should be within #{max_diff}s"
end
end
end
end
Expand Down

0 comments on commit 67373e0

Please sign in to comment.