Module: QAT::Cucumber::Time

Includes:
Logger
Included in:
QAT::Cucumber
Defined in:
lib/qat/cucumber/time.rb

Overview

Helper methods for time sync

Since:

  • 2.0.2

Constant Summary collapse

MANDATORY_KEYS =

Mandatory keys for time sync

Since:

  • 2.0.2

[:sync]

Instance Method Summary collapse

Instance Method Details

#set_time_zone(time_zone) ⇒ Object

Sets the time zone

Parameters:

  • time_zone (String)

    time zone

Since:

  • 2.0.2



50
51
52
# File 'lib/qat/cucumber/time.rb', line 50

def set_time_zone(time_zone)
  QAT::Time.zone = time_zone if time_zone
end

#start_time_sync(target, sync_options) ⇒ Object

Does the time sync with the target host

Parameters:

  • target (Array)

    host, method of sync, options

  • sync_options (Hash)

    sync options

Since:

  • 2.0.2



37
38
39
40
41
42
43
44
45
46
# File 'lib/qat/cucumber/time.rb', line 37

def start_time_sync(target, sync_options)
  QAT::Time.synchronize(*target)
rescue => exception
  if sync_options[:kill_if_failed]
    raise
  else
    log.warn { "Synchronization failed but proceeding anyway! [(#{exception.class}) #{exception.message}]" }
    log.debug exception
  end
end

#time_syncObject

Does the time synchronization between the host running tests and a target host

Since:

  • 2.0.2



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/qat/cucumber/time.rb', line 12

def time_sync
  time = validate_time_options

  sync_options = time[:sync]
  log.info { "Syncing with host #{sync_options[:host]}." }
  target = sync_options.values_at(:host, :method, :opts)

  start_time_sync(target, sync_options)

  set_time_zone(time[:zone])
end

#validate_time_optionsObject

validates that the necessary options are present

Since:

  • 2.0.2



25
26
27
28
29
30
31
32
# File 'lib/qat/cucumber/time.rb', line 25

def validate_time_options
  time    = QAT.configuration[:time].deep_symbolize_keys
  missing = MANDATORY_KEYS - time.keys

  raise InvalidConfiguration.new "Time configuration is not valid! Missing: #{missing.join(', ')}" if missing.any?

  time
end