Skip to content

Commit

Permalink
Fix ruby tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Sep 5, 2024
1 parent 6c562a8 commit ef87414
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion openc3/lib/openc3/models/tool_config_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions openc3/spec/microservices/interface_microservice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down
6 changes: 3 additions & 3 deletions openc3/spec/microservices/router_microservice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ef87414

Please sign in to comment.