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

disable sending watchdogs during clock tests, fixes #355 #358

Merged
merged 2 commits into from
Dec 13, 2023
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
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
@@ -1,4 +1,5 @@
RSpec.describe 'Site::Core' do
include Validator::CommandHelpers

# Check that the site closed the connection as required when faced with
# various types of incorrect behaviour from our side.
Expand Down Expand Up @@ -37,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 @@ -45,9 +47,9 @@ def site_proxy.acknowledge original
end

log "Stop sending watchdogs, site should not disconnect"
def site.send_watchdog now=nil
site.with_watchdog_disabled do
wait_task.wait
end
wait_task.wait
end
end
end
Expand Down
210 changes: 114 additions & 96 deletions spec/site/tlc/clock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# Tests related to the clock.
# When you set the clock, the adjusted time should be used
# everywhere you get back a timestamp.
# Note that watchdog messages can be used to synchronize the clock,
# which can interfere with our tests. So we disable sending watchdogs
# during tests.


describe 'Clock' do
CLOCK = Time.new 2020,9,29,17,29,51,'+00:00'
Expand Down Expand Up @@ -50,39 +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
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 @@ -97,28 +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
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 @@ -134,16 +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
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 @@ -158,14 +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
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 @@ -180,14 +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
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 @@ -206,13 +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
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 @@ -228,15 +244,17 @@
it 'is used for watchdog timestamp', sxl: '>=1.0.7' do |example|
Validator::Site.connected do |task,supervisor,site|
prepare task, site
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
7 changes: 7 additions & 0 deletions spec/support/command_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,13 @@ def reset_clock
send_command_and_confirm @task, command_list, "Reset clock to #{now}"
end

def stop_sending_watchdogs(site)
# monkey-patch the site object by redefining
# the send_watchdog method to do nothing
def site.send_watchdog now=nil
end
end

def with_clock_set clock, &block
result = set_clock clock
yield result
Expand Down