diff --git a/spec/site/core/disconnect_spec.rb b/spec/site/core/disconnect_spec.rb index fe79fb17..8cd529c3 100644 --- a/spec/site/core/disconnect_spec.rb +++ b/spec/site/core/disconnect_spec.rb @@ -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. @@ -45,8 +46,7 @@ def site_proxy.acknowledge original end log "Stop sending watchdogs, site should not disconnect" - def site.send_watchdog now=nil - end + stop_sending_watchdogs(site) wait_task.wait end end diff --git a/spec/site/tlc/clock_spec.rb b/spec/site/tlc/clock_spec.rb index 94253e6a..4446da4d 100644 --- a/spec/site/tlc/clock_spec.rb +++ b/spec/site/tlc/clock_spec.rb @@ -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' @@ -50,6 +54,7 @@ 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, @@ -97,6 +102,7 @@ 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, @@ -134,6 +140,7 @@ 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'] @@ -158,6 +165,7 @@ 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] @@ -180,6 +188,7 @@ 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] @@ -206,6 +215,7 @@ 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"] ) @@ -228,6 +238,7 @@ 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'] diff --git a/spec/support/command_helpers.rb b/spec/support/command_helpers.rb index ebaa3960..e2bc7296 100644 --- a/spec/support/command_helpers.rb +++ b/spec/support/command_helpers.rb @@ -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