Skip to content

Commit

Permalink
Rubocop Minitest/EmptyLineBeforeAssertionMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle committed Oct 31, 2022
1 parent 2f35fb8 commit 9be0b17
Show file tree
Hide file tree
Showing 292 changed files with 2,096 additions and 11 deletions.
1 change: 1 addition & 0 deletions infinite_tracing/test/infinite_tracing/channel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_compression_enabled_returns_false

def test_invalid_compression_level
channel = Channel.new

refute channel.valid_compression_level?(:bogus)
end

Expand Down
2 changes: 2 additions & 0 deletions infinite_tracing/test/infinite_tracing/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def test_record_spans_is_used_if_batching_is_not_enabled
# by overriding #record_spans to return a known canned string
def client.record_spans(*args); 'correct'; end
client.start_streaming

assert_equal 'correct', client.instance_variable_get(:@response_handler)
end
end
Expand All @@ -181,6 +182,7 @@ def test_record_span_batches_is_used_if_batching_is_enabled
# by overriding #record_span_batches to return a known canned string
def client.record_span_batches(*args); 'correct'; end
client.start_streaming

assert_equal 'correct', client.instance_variable_get(:@response_handler)
end
end
Expand Down
2 changes: 2 additions & 0 deletions infinite_tracing/test/infinite_tracing/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def setup

def test_all_infinite_tracing_config_keys_are_used
scan_and_remove_used_entries(@default_keys, non_test_files)

assert_empty @default_keys
end

Expand Down Expand Up @@ -101,6 +102,7 @@ def test_unset_trace_observer_host_raises_error
error = assert_raises RuntimeError do
Config.trace_observer_uri
end

assert_match(/not configured/, error.message)
end

Expand Down
3 changes: 3 additions & 0 deletions infinite_tracing/test/infinite_tracing/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def test_connection_reconnects
simulate_connect_to_collector(fiddlesticks_config, 0.0) do |simulator|
simulator.join
metadata = connection.send(:metadata)

assert_equal "swiss_cheese", metadata["license_key"]
assert_equal "fiddlesticks", metadata["agent_run_token"]

Expand All @@ -88,6 +89,7 @@ def test_sending_spans_to_server
with_serial_lock do
total_spans = 5
spans, segments = emulate_streaming_segments(total_spans)

assert_equal total_spans, segments.size
assert_equal total_spans, spans.size
end
Expand Down Expand Up @@ -194,6 +196,7 @@ def test_metadata_includes_request_headers_map
# Testing the backoff similarly to connect_test.rb
def test_increment_retry_period
unstub_reconnection

assert_equal 15, next_retry_period
assert_equal 15, next_retry_period
assert_equal 30, next_retry_period
Expand Down
3 changes: 3 additions & 0 deletions infinite_tracing/test/infinite_tracing/transformer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ module InfiniteTracing
class TransformerTest < Minitest::Test
def test_transforms_single_span_event
span_event = Transformer.transform(span_event_fixture(:single))

assert_kind_of Hash, span_event
assert_equal "cb4925eee573c1f9c786fdb2b296459b", span_event["trace_id"]
span_event["intrinsics"].each do |key, value|
assert_kind_of String, key
assert_kind_of AttributeValue, value
end

assert_empty span_event["user_attributes"]
assert_empty span_event["agent_attributes"]
end

def test_transforms_single_full_span_event
span_event = Transformer.transform(span_event_fixture(:single_full_attributes))

assert_kind_of Hash, span_event
assert_equal "cb4925eee573c1f9c786fdb2b296459b", span_event["trace_id"]

Expand Down
3 changes: 3 additions & 0 deletions infinite_tracing/test/infinite_tracing/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ def test_processes_simple_task
worker = Worker.new("simple") do
NewRelic::Agent.record_metric("Supportability/InfiniteTracing/Worker", 0.0)
end

assert_equal "run", worker.status
worker.join

assert_equal "idle", worker.status
worker.stop

assert_equal "stopped", worker.status

assert_equal "simple", worker.name
Expand Down
1 change: 1 addition & 0 deletions infinite_tracing/test/infinite_tracing_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_version_matches_agent_version

def test_span_events_fixtures_load
span_event = span_event_fixture(:single)

assert_kind_of Array, span_event
assert_kind_of Hash, span_event[0]
assert_kind_of Hash, span_event[1]
Expand Down
2 changes: 2 additions & 0 deletions infinite_tracing/test/support/fake_trace_observer_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def unstub_reconnection

def assert_only_one_subscription_notifier
still_subscribed = NewRelic::Agent.agent.events.still_subscribed(:server_source_configuration_added)

assert_equal 1, still_subscribed.size
end

Expand All @@ -55,6 +56,7 @@ def teardown
@mock_thread = nil
@server_response_enum = nil
reset_buffers_and_caches

assert_only_one_subscription_notifier
reset_infinite_tracer
unstub_reconnection
Expand Down
1 change: 1 addition & 0 deletions infinite_tracing/test/support/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def fixtures_path

def span_event_fixture(fixture_name)
fixture_filename = File.join(fixtures_path, "span_events", "#{fixture_name}.yml")

assert_path_exists(fixture_filename, "Missing Span Event Fixture: #{fixture_name}. Looked for #{fixture_filename}")
if YAML.respond_to?(:unsafe_load)
YAML::unsafe_load(File.read(fixture_filename))
Expand Down
17 changes: 17 additions & 0 deletions test/agent_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def reset_error_traces!

def assert_has_traced_error(error_class)
errors = harvest_error_traces!

refute_nil errors.find { |e| e.exception_class_name == error_class.name }, \
"Didn't find error of class #{error_class}"
end
Expand Down Expand Up @@ -83,13 +84,15 @@ def last_error_event
unless defined? assert_includes
def assert_includes(collection, member, msg = nil)
msg = "Expected #{collection.inspect} to include #{member.inspect}"

assert_includes collection, member, msg
end
end

unless defined? assert_not_includes
def assert_not_includes(collection, member, msg = nil)
msg = "Expected #{collection.inspect} not to include #{member.inspect}"

refute_includes collection, member, msg
end
end
Expand All @@ -107,6 +110,7 @@ def assert_equal_unordered(left, right)

def assert_log_contains(log, message)
lines = log.array

assert (lines.any? { |line| line.match(message) })
end

Expand All @@ -117,6 +121,7 @@ def assert_audit_log_contains(audit_log_contents, needle)
regex = /[:"]/
needle = needle.gsub(regex, '')
haystack = audit_log_contents.gsub(regex, '')

assert_includes(haystack, needle, "Expected log to contain '#{needle}'")
end

Expand All @@ -140,6 +145,7 @@ def assert_audit_log_contains_object(audit_log_contents, o, format = :json)
assert_audit_log_contains_object(audit_log_contents, el, format)
end
when NilClass

assert_audit_log_contains(audit_log_contents, format == :json ? "null" : "nil")
else
assert_audit_log_contains(audit_log_contents, o.inspect)
Expand All @@ -148,6 +154,7 @@ def assert_audit_log_contains_object(audit_log_contents, o, format = :json)

def compare_metrics(expected, actual)
actual.delete_if { |a| a.include?('GC/Transaction/') }

assert_equal(expected.to_a.sort, actual.to_a.sort, "extra: #{(actual - expected).to_a.inspect}; missing: #{(expected - actual).to_a.inspect}")
end

Expand Down Expand Up @@ -206,6 +213,7 @@ def assert_stats_has_values_with_call_count(expected_value, actual_value, msg)
if expected_value.to_s =~ /([<>]=?)\s*(\d+)/
operator = Regexp.last_match(1).to_sym
count = Regexp.last_match(2).to_i

assert_operator(actual_value, operator, count, msg)
# == comparison
else
Expand All @@ -229,6 +237,7 @@ def assert_metrics_recorded(expected)

assert(actual_stats, msg) # rubocop:disable Minitest/AssertWithExpectedArgument
end

assert_stats_has_values(actual_stats, expected_spec, expected_attrs)
end
end
Expand All @@ -246,6 +255,7 @@ def assert_metrics_recorded(expected)
#
def assert_metrics_recorded_exclusive(expected, options = {})
expected = _normalize_metric_expectations(expected)

assert_metrics_recorded(expected)

recorded_metrics = NewRelic::Agent.instance.stats_engine.to_h.keys
Expand Down Expand Up @@ -300,6 +310,7 @@ def assert_metrics_not_recorded(not_expected)
found_but_not_expected << spec
end
end

assert_empty(found_but_not_expected, "Found unexpected metrics: #{format_metric_spec_list(found_but_not_expected)}")
end

Expand Down Expand Up @@ -328,11 +339,13 @@ def format_metric_spec_list(specs)

def assert_truthy(expected, msg = nil)
msg ||= "Expected #{expected.inspect} to be truthy"

refute !expected, msg
end

def assert_falsy(expected, msg = nil)
msg ||= "Expected #{expected.inspect} to be falsy"

refute expected, msg
end

Expand Down Expand Up @@ -888,6 +901,7 @@ def assert_event_attributes(event, test_name, expected_attributes, non_expected_
event_attrs.each do |name, actual_value|
msg << " #{name}: #{actual_value.inspect}\n"
end

assert_empty(incorrect_attributes, msg)

non_expected_attributes.each do |name|
Expand Down Expand Up @@ -950,6 +964,7 @@ def assert_match_or_equal(expected, value)
# the expectations against it.
def assert_segment_noticed_error(txn, segment_name, error_classes, error_message)
error_segment = txn.segments.reverse.detect { |s| s.noticed_error }

assert error_segment, "Expected at least one segment with a noticed_error"

assert_match_or_equal segment_name, error_segment.name
Expand All @@ -967,6 +982,7 @@ def assert_transaction_noticed_error(txn, error_classes)

def refute_transaction_noticed_error(txn, error_class)
error_segment = txn.segments.reverse.detect { |s| s.noticed_error }

assert error_segment, "Expected at least one segment with a noticed_error"
assert_empty txn.exceptions, "Expected transaction to NOT notice any segment errors"
end
Expand All @@ -984,6 +1000,7 @@ def refute_raises(*exp)
rescue Exception => e
puts "EXCEPTION RAISED: #{e.inspect}\n#{e.backtrace}"
exp = exp.first if exp.size == 1

flunk(msg || "unexpected exception raised: #{e}")
end
end
Expand Down
4 changes: 4 additions & 0 deletions test/multiverse/suites/active_record/active_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ def test_only_supportability_metrics_recorded_with_disable_all_tracing
Order.first
end
end

refute last_transaction_trace
assert_metrics_recorded_exclusive([
"Supportability/API/disable_all_tracing",
Expand All @@ -491,9 +492,11 @@ def test_records_transaction_trace_nodes
sample = last_transaction_trace
metric = "Datastore/statement/#{current_product}/Order/find"
node = find_node_with_name(sample, metric)

assert_equal(metric, node.metric_name)

statement = node.params[:sql]

assert_match(/^SELECT /, statement.sql)

assert_match(statement.adapter.to_s, adapter.to_s)
Expand Down Expand Up @@ -530,6 +533,7 @@ def test_sql_samplers_get_proper_metrics
end

metric = "Datastore/statement/#{current_product}/Order/find"

refute_nil find_sql_trace(metric)
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/multiverse/suites/active_record/ar_method_aliasing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class InstrumentActiveRecordMethods < Minitest::Test

def test_basic_creation
a_user = User.new(:name => "Bob")

assert a_user.new_record?
a_user.save!

Expand All @@ -28,9 +29,11 @@ def test_alias_collection_query_method
a_user.save!

a_user = User.first

assert User.connected?

an_alias = Alias.new(:user_id => a_user.id, :aka => "the Blob")

assert an_alias.new_record?
an_alias.save!
assert an_alias.persisted? if a_user.respond_to?(:persisted?)
Expand Down
4 changes: 4 additions & 0 deletions test/multiverse/suites/active_record_pg/active_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ def test_only_supportability_metrics_recorded_with_disable_all_tracing
Order.first
end
end

refute last_transaction_trace
assert_metrics_recorded_exclusive([
"Supportability/API/disable_all_tracing",
Expand All @@ -475,9 +476,11 @@ def test_records_transaction_trace_nodes
sample = last_transaction_trace
metric = "Datastore/statement/#{current_product}/Order/find"
node = find_node_with_name(sample, metric)

assert_equal(metric, node.metric_name)

statement = node.params[:sql]

assert_match(/^SELECT /, statement.sql)

assert_match(statement.adapter.to_s, adapter.to_s)
Expand Down Expand Up @@ -514,6 +517,7 @@ def test_sql_samplers_get_proper_metrics
end

metric = "Datastore/statement/#{current_product}/Order/find"

refute_nil find_sql_trace(metric)
end
end
Expand Down
3 changes: 3 additions & 0 deletions test/multiverse/suites/active_record_pg/ar_method_aliasing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class InstrumentActiveRecordMethods < Minitest::Test

def test_basic_creation
a_user = User.new(:name => "Bob")

assert a_user.new_record?
a_user.save!

Expand All @@ -28,9 +29,11 @@ def test_alias_collection_query_method
a_user.save!

a_user = User.first

assert User.connected?

an_alias = Alias.new(:user_id => a_user.id, :aka => "the Blob")

assert an_alias.new_record?
an_alias.save!
assert an_alias.persisted? if a_user.respond_to?(:persisted?)
Expand Down
2 changes: 2 additions & 0 deletions test/multiverse/suites/activemerchant/activemerchant_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_noticed_error_at_segment_and_txn_on_error
rescue StandardError => e
# NOP -- allowing span and transaction to notice error
end

assert_segment_noticed_error txn, /ActiveMerchant\/gateway/, expected_error_class, /whoops/i
assert_transaction_noticed_error txn, expected_error_class
end
Expand Down Expand Up @@ -103,6 +104,7 @@ def assert_merchant_transaction(operation, *args)

gateway.send(operation, *args)
end

assert_metrics_recorded([
["ActiveMerchant/gateway/BogusGateway/#{operation}", "txn"],
"ActiveMerchant/gateway/BogusGateway",
Expand Down
2 changes: 2 additions & 0 deletions test/multiverse/suites/agent_only/adaptive_sampler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_adaptive_sampler_valid_stats_and_reset_after_harvest
end

stats = NewRelic::Agent.instance.adaptive_sampler.stats

assert_equal 0, stats[:seen_last]
assert_equal 20, stats[:seen]
assert_equal sampled_count, stats[:sampled_count]
Expand All @@ -33,6 +34,7 @@ def test_adaptive_sampler_valid_stats_and_reset_after_harvest
in_transaction("test_txn_20") {}

stats = NewRelic::Agent.instance.adaptive_sampler.stats

assert_equal 1, stats[:seen]
assert_equal 20, stats[:seen_last]
end
Expand Down
Loading

0 comments on commit 9be0b17

Please sign in to comment.