From ef87414e82f44f550cb8d07efe1fbaf569527c61 Mon Sep 17 00:00:00 2001 From: Jason Thomas Date: Thu, 5 Sep 2024 15:30:28 -0600 Subject: [PATCH] Fix ruby tests --- openc3/lib/openc3/models/tool_config_model.rb | 2 +- .../spec/microservices/interface_microservice_spec.rb | 10 ++++++++-- openc3/spec/microservices/router_microservice_spec.rb | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/openc3/lib/openc3/models/tool_config_model.rb b/openc3/lib/openc3/models/tool_config_model.rb index 330b92bca0..abf73a5df0 100644 --- a/openc3/lib/openc3/models/tool_config_model.rb +++ b/openc3/lib/openc3/models/tool_config_model.rb @@ -25,7 +25,7 @@ module OpenC3 class ToolConfigModel def self.config_tool_names(scope: $openc3_scope) - cursor, keys = Store.scan(0, match: "#{scope}__config__*", type: 'hash', count: 100) + _, keys = Store.scan(0, match: "#{scope}__config__*", type: 'hash', count: 100) # Just return the tool name that is used in the other APIs return keys.map! { |key| key.split('__')[2] }.sort end diff --git a/openc3/spec/microservices/interface_microservice_spec.rb b/openc3/spec/microservices/interface_microservice_spec.rb index b52ac7e6b6..78ac597ef2 100644 --- a/openc3/spec/microservices/interface_microservice_spec.rb +++ b/openc3/spec/microservices/interface_microservice_spec.rb @@ -32,7 +32,7 @@ module OpenC3 describe InterfaceMicroservice do before(:each) do # This must be here in order to work when running more than this individual file - class TestInterface < Interface + class TestInterface < Interface # rubocop:disable Lint/ConstantDefinitionInBlock def initialize(hostname = "default", port = 12345) @hostname = hostname @port = port @@ -110,7 +110,7 @@ def read_interface CvtModel.set(json_hash, target_name: packet.target_name, packet_name: packet.packet_name, scope: "DEFAULT") end - class ApiTest + class ApiTest # rubocop:disable Lint/ConstantDefinitionInBlock include Extract include Api include Authorization @@ -266,8 +266,14 @@ class ApiTest interface = im.instance_variable_get(:@interface) interface.reconnect_delay = 0.1 # Override the reconnect delay to be quick + # Mock this because it calls exit which breaks SimpleCov + allow(OpenC3).to receive(:handle_fatal_exception) do |exception, _message| + expect(exception.message).to eql "test-error" + end + capture_io do |stdout| Thread.new { im.run } + sleep 0.1 # Allow to start and immediately crash expect(stdout.string).to include("RuntimeError") diff --git a/openc3/spec/microservices/router_microservice_spec.rb b/openc3/spec/microservices/router_microservice_spec.rb index 22eccb3224..48af84df9a 100644 --- a/openc3/spec/microservices/router_microservice_spec.rb +++ b/openc3/spec/microservices/router_microservice_spec.rb @@ -29,13 +29,13 @@ module OpenC3 describe RouterMicroservice do - class ApiTest + class ApiTest # rubocop:disable Lint/ConstantDefinitionInBlock include Extract include Api include Authorization end - class TestInterface < Interface + class TestRouter < Interface # rubocop:disable Lint/ConstantDefinitionInBlock def initialize super @connected = false @@ -82,7 +82,7 @@ def read_interface interface = double("Interface").as_null_object allow(interface).to receive(:connected?).and_return(true) allow(System).to receive(:targets).and_return({ "INST" => interface }) - model = RouterModel.new(name: "TEST_INT", scope: "DEFAULT", target_names: ["INST"], cmd_target_names: ["INST"], tlm_target_names: ["INST"], config_params: ["TestInterface"]) + model = RouterModel.new(name: "TEST_INT", scope: "DEFAULT", target_names: ["INST"], cmd_target_names: ["INST"], tlm_target_names: ["INST"], config_params: ["TestRouter"]) model.create model = MicroserviceModel.new(folder_name: "TEST", name: "DEFAULT__ROUTER__TEST_INT", scope: "DEFAULT", target_names: ["INST"]) model.create