Unlike the respirate smoke test, where we can run test strands, monitor is hard coded to use specific models. Change this so that when it runs in test mode, it uses a stubbed model, a new class named MonitorResourceStub. MonitorResourceStub stubs methods for both monitoring and metric exporting. It's designed to exercise most of monitor's surface area. This runs using four stubbed resources: * up: resource that always reports pulse as up * down: resource that always reports pulse as down * evloop: resource that uses an event loop * mc2: resource that reports a metric count of 2 For each resource, it checks for expected logged output. It runs 4 separate processes in different partitions. The stub doesn't respect the parititioning, and doesn't use the database. The smoke test does check that the logged messages show expected partitioning. Similar to the respirate smoke test, run the monitor smoke test in CI whenever a related file changes.
77 lines
1.3 KiB
Ruby
77 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Only used by the monitor smoke test
|
|
# :nocov:
|
|
class MonitorResourceStub
|
|
OBJECTS = []
|
|
|
|
class Session
|
|
def loop(sleep_for)
|
|
Kernel.loop do
|
|
sleep(sleep_for)
|
|
break unless yield
|
|
end
|
|
end
|
|
|
|
def shutdown!
|
|
nil
|
|
end
|
|
|
|
def close
|
|
nil
|
|
end
|
|
end
|
|
|
|
def self.add(...)
|
|
OBJECTS << new(...)
|
|
end
|
|
|
|
def self.where_each(_range, &)
|
|
OBJECTS.each(&)
|
|
end
|
|
|
|
def self.count
|
|
OBJECTS.size
|
|
end
|
|
|
|
attr_reader :id, :ubid
|
|
|
|
def initialize(ubid, need_event_loop: false, pulse: "up", metrics_count: 1)
|
|
@id = ubid.to_uuid
|
|
@ubid = ubid.to_s
|
|
@need_event_loop = need_event_loop
|
|
@pulse_count = 0
|
|
@pulse = pulse
|
|
@metrics_counts = metrics_count
|
|
end
|
|
|
|
def needs_event_loop_for_pulse_check?
|
|
@need_event_loop
|
|
end
|
|
|
|
def check_pulse(session:, previous_pulse:)
|
|
@pulse_count += 1
|
|
sleep(0.1 + rand)
|
|
{reading: @pulse, reading_rpt: @pulse_count}
|
|
end
|
|
|
|
def export_metrics(session:, tsdb_client:)
|
|
sleep(0.1 + rand)
|
|
@metrics_counts
|
|
end
|
|
|
|
def reload
|
|
self
|
|
end
|
|
|
|
def init_health_monitor_session
|
|
{ssh_session: Session.new}
|
|
end
|
|
alias_method :init_metrics_export_session, :init_health_monitor_session
|
|
|
|
def metrics_config
|
|
{}
|
|
end
|
|
end
|
|
# :nocov:
|