statsd-instrument 2.9.2 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +16 -23
  3. data/.rubocop.yml +3 -13
  4. data/CHANGELOG.md +33 -0
  5. data/Gemfile +8 -0
  6. data/README.md +3 -3
  7. data/Rakefile +1 -1
  8. data/benchmark/send-metrics-to-dev-null-log +5 -2
  9. data/benchmark/send-metrics-to-local-udp-receiver +8 -6
  10. data/bin/rake +29 -0
  11. data/bin/rubocop +29 -0
  12. data/lib/statsd/instrument.rb +80 -144
  13. data/lib/statsd/instrument/assertions.rb +200 -208
  14. data/lib/statsd/instrument/capture_sink.rb +23 -19
  15. data/lib/statsd/instrument/client.rb +414 -320
  16. data/lib/statsd/instrument/datagram.rb +69 -65
  17. data/lib/statsd/instrument/datagram_builder.rb +81 -77
  18. data/lib/statsd/instrument/dogstatsd_datagram.rb +76 -72
  19. data/lib/statsd/instrument/dogstatsd_datagram_builder.rb +68 -64
  20. data/lib/statsd/instrument/environment.rb +79 -98
  21. data/lib/statsd/instrument/expectation.rb +96 -96
  22. data/lib/statsd/instrument/helpers.rb +10 -35
  23. data/lib/statsd/instrument/log_sink.rb +20 -16
  24. data/lib/statsd/instrument/matchers.rb +86 -71
  25. data/lib/statsd/instrument/null_sink.rb +12 -8
  26. data/lib/statsd/instrument/railtie.rb +11 -11
  27. data/lib/statsd/instrument/statsd_datagram_builder.rb +12 -8
  28. data/lib/statsd/instrument/strict.rb +12 -123
  29. data/lib/statsd/instrument/udp_sink.rb +50 -46
  30. data/lib/statsd/instrument/version.rb +1 -1
  31. data/statsd-instrument.gemspec +2 -8
  32. data/test/assertions_test.rb +46 -12
  33. data/test/capture_sink_test.rb +8 -8
  34. data/test/client_test.rb +62 -51
  35. data/test/datagram_builder_test.rb +29 -29
  36. data/test/datagram_test.rb +1 -1
  37. data/test/dogstatsd_datagram_builder_test.rb +28 -28
  38. data/test/environment_test.rb +10 -46
  39. data/test/helpers/rubocop_helper.rb +11 -8
  40. data/test/helpers_test.rb +5 -5
  41. data/test/integration_test.rb +10 -25
  42. data/test/log_sink_test.rb +2 -2
  43. data/test/matchers_test.rb +36 -36
  44. data/test/null_sink_test.rb +2 -2
  45. data/test/rubocop/metric_return_value_test.rb +3 -3
  46. data/test/rubocop/metric_value_keyword_argument_test.rb +1 -1
  47. data/test/rubocop/positional_arguments_test.rb +10 -10
  48. data/test/statsd_instrumentation_test.rb +97 -122
  49. data/test/statsd_test.rb +50 -75
  50. data/test/test_helper.rb +7 -5
  51. data/test/udp_sink_test.rb +8 -8
  52. metadata +7 -125
  53. data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
  54. data/benchmark/datagram-client +0 -40
  55. data/lib/statsd/instrument/backend.rb +0 -18
  56. data/lib/statsd/instrument/backends/capture_backend.rb +0 -32
  57. data/lib/statsd/instrument/backends/logger_backend.rb +0 -20
  58. data/lib/statsd/instrument/backends/null_backend.rb +0 -9
  59. data/lib/statsd/instrument/backends/udp_backend.rb +0 -152
  60. data/lib/statsd/instrument/legacy_client.rb +0 -301
  61. data/lib/statsd/instrument/metric.rb +0 -155
  62. data/test/assertions_on_legacy_client_test.rb +0 -344
  63. data/test/capture_backend_test.rb +0 -26
  64. data/test/compatibility/dogstatsd_datagram_compatibility_test.rb +0 -161
  65. data/test/deprecations_test.rb +0 -139
  66. data/test/logger_backend_test.rb +0 -22
  67. data/test/metric_test.rb +0 -47
  68. data/test/udp_backend_test.rb +0 -228
@@ -8,111 +8,111 @@ class DatagramBuilderTest < Minitest::Test
8
8
  end
9
9
 
10
10
  def test_normalize_name
11
- assert_equal 'foo', @datagram_builder.send(:normalize_name, 'foo')
12
- assert_equal 'fo_o', @datagram_builder.send(:normalize_name, 'fo|o')
13
- assert_equal 'fo_o', @datagram_builder.send(:normalize_name, 'fo@o')
14
- assert_equal 'fo_o', @datagram_builder.send(:normalize_name, 'fo:o')
11
+ assert_equal('foo', @datagram_builder.send(:normalize_name, 'foo'))
12
+ assert_equal('fo_o', @datagram_builder.send(:normalize_name, 'fo|o'))
13
+ assert_equal('fo_o', @datagram_builder.send(:normalize_name, 'fo@o'))
14
+ assert_equal('fo_o', @datagram_builder.send(:normalize_name, 'fo:o'))
15
15
  end
16
16
 
17
17
  def test_normalize_unsupported_tag_names
18
- assert_equal ['ign#ored'], @datagram_builder.send(:normalize_tags, ['ign#o|re,d'])
18
+ assert_equal(['ign#ored'], @datagram_builder.send(:normalize_tags, ['ign#o|re,d']))
19
19
  # Note: how this is interpreted by the backend is undefined.
20
20
  # We rely on the user to not do stuff like this if they don't want to be surprised.
21
21
  # We do not want to take the performance hit of normalizing this.
22
- assert_equal ['lol::class:omg::lol'], @datagram_builder.send(:normalize_tags, "lol::class" => "omg::lol")
22
+ assert_equal(['lol::class:omg::lol'], @datagram_builder.send(:normalize_tags, "lol::class" => "omg::lol"))
23
23
  end
24
24
 
25
25
  def test_normalize_tags_converts_hash_to_array
26
- assert_equal ['tag:value'], @datagram_builder.send(:normalize_tags, tag: 'value')
27
- assert_equal ['tag1:v1', 'tag2:v2'], @datagram_builder.send(:normalize_tags, tag1: 'v1', tag2: 'v2')
26
+ assert_equal(['tag:value'], @datagram_builder.send(:normalize_tags, tag: 'value'))
27
+ assert_equal(['tag1:v1', 'tag2:v2'], @datagram_builder.send(:normalize_tags, tag1: 'v1', tag2: 'v2'))
28
28
  end
29
29
 
30
30
  def test_c
31
31
  datagram = @datagram_builder.c('foo', 1, nil, nil)
32
- assert_equal "foo:1|c", datagram
32
+ assert_equal("foo:1|c", datagram)
33
33
 
34
34
  datagram = @datagram_builder.c('fo:o', 10, 0.1, nil)
35
- assert_equal "fo_o:10|c|@0.1", datagram
35
+ assert_equal("fo_o:10|c|@0.1", datagram)
36
36
  end
37
37
 
38
38
  def test_ms
39
39
  datagram = @datagram_builder.ms('foo', 1, nil, nil)
40
- assert_equal "foo:1|ms", datagram
40
+ assert_equal("foo:1|ms", datagram)
41
41
 
42
42
  datagram = @datagram_builder.ms('fo:o', 10, 0.1, nil)
43
- assert_equal "fo_o:10|ms|@0.1", datagram
43
+ assert_equal("fo_o:10|ms|@0.1", datagram)
44
44
  end
45
45
 
46
46
  def test_g
47
47
  datagram = @datagram_builder.g('foo', 1, nil, nil)
48
- assert_equal "foo:1|g", datagram
48
+ assert_equal("foo:1|g", datagram)
49
49
 
50
50
  datagram = @datagram_builder.g('fo|o', 10, 0.01, nil)
51
- assert_equal "fo_o:10|g|@0.01", datagram
51
+ assert_equal("fo_o:10|g|@0.01", datagram)
52
52
  end
53
53
 
54
54
  def test_s
55
55
  datagram = @datagram_builder.s('foo', 1, nil, nil)
56
- assert_equal "foo:1|s", datagram
56
+ assert_equal("foo:1|s", datagram)
57
57
 
58
58
  datagram = @datagram_builder.s('fo@o', 10, 0.01, nil)
59
- assert_equal "fo_o:10|s|@0.01", datagram
59
+ assert_equal("fo_o:10|s|@0.01", datagram)
60
60
  end
61
61
 
62
62
  def test_h
63
63
  datagram = @datagram_builder.h('foo', 1, nil, nil)
64
- assert_equal "foo:1|h", datagram
64
+ assert_equal("foo:1|h", datagram)
65
65
 
66
66
  datagram = @datagram_builder.h('fo@o', 10, 0.01, nil)
67
- assert_equal "fo_o:10|h|@0.01", datagram
67
+ assert_equal("fo_o:10|h|@0.01", datagram)
68
68
  end
69
69
 
70
70
  def test_d
71
71
  datagram = @datagram_builder.d('foo', 1, nil, nil)
72
- assert_equal "foo:1|d", datagram
72
+ assert_equal("foo:1|d", datagram)
73
73
 
74
74
  datagram = @datagram_builder.d('fo@o', 10, 0.01, nil)
75
- assert_equal "fo_o:10|d|@0.01", datagram
75
+ assert_equal("fo_o:10|d|@0.01", datagram)
76
76
  end
77
77
 
78
78
  def test_tags
79
79
  datagram = @datagram_builder.d('foo', 10, nil, ['foo', 'bar'])
80
- assert_equal "foo:10|d|#foo,bar", datagram
80
+ assert_equal("foo:10|d|#foo,bar", datagram)
81
81
 
82
82
  datagram = @datagram_builder.d('foo', 10, 0.1, ['foo:bar'])
83
- assert_equal "foo:10|d|@0.1|#foo:bar", datagram
83
+ assert_equal("foo:10|d|@0.1|#foo:bar", datagram)
84
84
 
85
85
  datagram = @datagram_builder.d('foo', 10, 1, foo: 'bar', baz: 'quc')
86
- assert_equal "foo:10|d|#foo:bar,baz:quc", datagram
86
+ assert_equal("foo:10|d|#foo:bar,baz:quc", datagram)
87
87
  end
88
88
 
89
89
  def test_prefix
90
90
  datagram_builder = StatsD::Instrument::DatagramBuilder.new(prefix: 'foo')
91
91
  datagram = datagram_builder.c('bar', 1, nil, nil)
92
- assert_equal 'foo.bar:1|c', datagram
92
+ assert_equal('foo.bar:1|c', datagram)
93
93
 
94
94
  # The prefix should also be normalized
95
95
  datagram_builder = StatsD::Instrument::DatagramBuilder.new(prefix: 'foo|bar')
96
96
  datagram = datagram_builder.c('baz', 1, nil, nil)
97
- assert_equal 'foo_bar.baz:1|c', datagram
97
+ assert_equal('foo_bar.baz:1|c', datagram)
98
98
  end
99
99
 
100
100
  def test_default_tags
101
101
  datagram_builder = StatsD::Instrument::DatagramBuilder.new(default_tags: ['foo'])
102
102
  datagram = datagram_builder.c('bar', 1, nil, nil)
103
- assert_equal 'bar:1|c|#foo', datagram
103
+ assert_equal('bar:1|c|#foo', datagram)
104
104
 
105
105
  datagram = datagram_builder.c('bar', 1, nil, a: 'b')
106
- assert_equal 'bar:1|c|#a:b,foo', datagram
106
+ assert_equal('bar:1|c|#a:b,foo', datagram)
107
107
 
108
108
  # We do not filter out duplicates, because detecting dupes is too time consuming.
109
109
  # We let the server deal with the situation
110
110
  datagram = datagram_builder.c('bar', 1, nil, ['foo'])
111
- assert_equal 'bar:1|c|#foo,foo', datagram
111
+ assert_equal('bar:1|c|#foo,foo', datagram)
112
112
 
113
113
  # Default tags are also normalized
114
114
  datagram_builder = StatsD::Instrument::DatagramBuilder.new(default_tags: ['f,o|o'])
115
115
  datagram = datagram_builder.c('bar', 1, nil, nil)
116
- assert_equal 'bar:1|c|#foo', datagram
116
+ assert_equal('bar:1|c|#foo', datagram)
117
117
  end
118
118
  end
@@ -9,6 +9,6 @@ class DatagramTest < Minitest::Test
9
9
  'multi_currency:false,fulfillment_orders_beta_enabled:false'
10
10
 
11
11
  parsed = StatsD::Instrument::Datagram.new(datagram)
12
- assert_includes parsed.tags, 'code_source:NilController#NilAction'
12
+ assert_includes(parsed.tags, 'code_source:NilController#NilAction')
13
13
  end
14
14
  end
@@ -13,55 +13,55 @@ class DogStatsDDatagramBuilderTest < Minitest::Test
13
13
 
14
14
  def test_simple_service_check
15
15
  datagram = @datagram_builder._sc('service', :ok)
16
- assert_equal '_sc|service|0', datagram
16
+ assert_equal('_sc|service|0', datagram)
17
17
  parsed_datagram = StatsD::Instrument::DogStatsDDatagramBuilder.datagram_class.new(datagram)
18
- assert_equal :_sc, parsed_datagram.type
19
- assert_equal 'service', parsed_datagram.name
20
- assert_equal 0, parsed_datagram.value
18
+ assert_equal(:_sc, parsed_datagram.type)
19
+ assert_equal('service', parsed_datagram.name)
20
+ assert_equal(0, parsed_datagram.value)
21
21
  end
22
22
 
23
23
  def test_complex_service_check
24
24
  datagram = @datagram_builder._sc('service', :warning, timestamp: Time.parse('2019-09-30T04:22:12Z'),
25
25
  hostname: 'localhost', tags: { foo: 'bar|baz' }, message: 'blah')
26
- assert_equal "_sc|service|1|h:localhost|d:1569817332|#foo:barbaz|m:blah", datagram
26
+ assert_equal("_sc|service|1|h:localhost|d:1569817332|#foo:barbaz|m:blah", datagram)
27
27
 
28
28
  parsed_datagram = StatsD::Instrument::DogStatsDDatagramBuilder.datagram_class.new(datagram)
29
- assert_equal :_sc, parsed_datagram.type
30
- assert_equal 'service', parsed_datagram.name
31
- assert_equal 1, parsed_datagram.value
32
- assert_equal 'localhost', parsed_datagram.hostname
33
- assert_equal Time.parse('2019-09-30T04:22:12Z'), parsed_datagram.timestamp
34
- assert_equal ["foo:barbaz"], parsed_datagram.tags
35
- assert_equal 'blah', parsed_datagram.message
29
+ assert_equal(:_sc, parsed_datagram.type)
30
+ assert_equal('service', parsed_datagram.name)
31
+ assert_equal(1, parsed_datagram.value)
32
+ assert_equal('localhost', parsed_datagram.hostname)
33
+ assert_equal(Time.parse('2019-09-30T04:22:12Z'), parsed_datagram.timestamp)
34
+ assert_equal(["foo:barbaz"], parsed_datagram.tags)
35
+ assert_equal('blah', parsed_datagram.message)
36
36
  end
37
37
 
38
38
  def test_simple_event
39
39
  datagram = @datagram_builder._e('hello', "world")
40
- assert_equal '_e{5,5}:hello|world', datagram
40
+ assert_equal('_e{5,5}:hello|world', datagram)
41
41
 
42
42
  parsed_datagram = StatsD::Instrument::DogStatsDDatagramBuilder.datagram_class.new(datagram)
43
- assert_equal :_e, parsed_datagram.type
44
- assert_equal 'hello', parsed_datagram.name
45
- assert_equal 'world', parsed_datagram.value
43
+ assert_equal(:_e, parsed_datagram.type)
44
+ assert_equal('hello', parsed_datagram.name)
45
+ assert_equal('world', parsed_datagram.value)
46
46
  end
47
47
 
48
48
  def test_complex_event
49
49
  datagram = @datagram_builder._e("testing", "with\nnewline", timestamp: Time.parse('2019-09-30T04:22:12Z'),
50
50
  hostname: 'localhost', aggregation_key: 'my-key', priority: 'low', source_type_name: 'source',
51
51
  alert_type: 'success', tags: { foo: 'bar|baz' })
52
- assert_equal '_e{7,13}:testing|with\\nnewline|h:localhost|d:1569817332|k:my-key|' \
53
- 'p:low|s:source|t:success|#foo:barbaz', datagram
52
+ assert_equal('_e{7,13}:testing|with\\nnewline|h:localhost|d:1569817332|k:my-key|' \
53
+ 'p:low|s:source|t:success|#foo:barbaz', datagram)
54
54
 
55
55
  parsed_datagram = StatsD::Instrument::DogStatsDDatagramBuilder.datagram_class.new(datagram)
56
- assert_equal :_e, parsed_datagram.type
57
- assert_equal 'testing', parsed_datagram.name
58
- assert_equal "with\nnewline", parsed_datagram.value
59
- assert_equal 'localhost', parsed_datagram.hostname
60
- assert_equal Time.parse('2019-09-30T04:22:12Z'), parsed_datagram.timestamp
61
- assert_equal ["foo:barbaz"], parsed_datagram.tags
62
- assert_equal "my-key", parsed_datagram.aggregation_key
63
- assert_equal "low", parsed_datagram.priority
64
- assert_equal "source", parsed_datagram.source_type_name
65
- assert_equal "success", parsed_datagram.alert_type
56
+ assert_equal(:_e, parsed_datagram.type)
57
+ assert_equal('testing', parsed_datagram.name)
58
+ assert_equal("with\nnewline", parsed_datagram.value)
59
+ assert_equal('localhost', parsed_datagram.hostname)
60
+ assert_equal(Time.parse('2019-09-30T04:22:12Z'), parsed_datagram.timestamp)
61
+ assert_equal(["foo:barbaz"], parsed_datagram.tags)
62
+ assert_equal("my-key", parsed_datagram.aggregation_key)
63
+ assert_equal("low", parsed_datagram.priority)
64
+ assert_equal("source", parsed_datagram.source_type_name)
65
+ assert_equal("success", parsed_datagram.alert_type)
66
66
  end
67
67
  end
@@ -5,90 +5,54 @@ require 'test_helper'
5
5
  module Rails; end
6
6
 
7
7
  class EnvironmentTest < Minitest::Test
8
- def setup
9
- ENV['STATSD_ADDR'] = nil
10
- ENV['IMPLEMENTATION'] = nil
11
- end
12
-
13
- def test_default_backend_uses_logger_in_development_environment
14
- StatsD::Instrument::Environment.stubs(:environment).returns('development')
15
- assert_instance_of StatsD::Instrument::Backends::LoggerBackend, StatsD::Instrument::Environment.default_backend
16
- end
17
-
18
- def test_default_backend_uses_null_backend_in_test_environment
19
- StatsD::Instrument::Environment.stubs(:environment).returns('test')
20
- assert_instance_of StatsD::Instrument::Backends::NullBackend, StatsD::Instrument::Environment.default_backend
21
- end
22
-
23
- def test_default_backend_uses_udp_backend_in_production_environment
24
- StatsD::Instrument::Environment.stubs(:environment).returns('production')
25
- assert_instance_of StatsD::Instrument::Backends::UDPBackend, StatsD::Instrument::Environment.default_backend
26
- end
27
-
28
- def test_default_backend_uses_environment_variables_in_production_environment
29
- StatsD::Instrument::Environment.stubs(:environment).returns('production')
30
- ENV['STATSD_ADDR'] = '127.0.0.1:1234'
31
- ENV['STATSD_IMPLEMENTATION'] = 'datadog'
32
-
33
- backend = StatsD::Instrument::Environment.default_backend
34
- assert_equal '127.0.0.1', backend.host
35
- assert_equal 1234, backend.port
36
- assert_equal :datadog, backend.implementation
37
- end
38
-
39
8
  def test_environment_prefers_statsd_env_if_available
40
9
  env = StatsD::Instrument::Environment.new(
41
10
  'STATSD_ENV' => 'set_from_STATSD_ENV',
42
11
  'RACK_ENV' => 'set_from_RACK_ENV',
43
12
  'ENV' => 'set_from_ENV',
44
13
  )
45
- assert_equal 'set_from_STATSD_ENV', env.environment
14
+ assert_equal('set_from_STATSD_ENV', env.environment)
46
15
  end
47
16
 
48
17
  def test_environment_uses_env_when_rails_does_not_respond_to_env_and_statsd_env_is_not_set
49
18
  env = StatsD::Instrument::Environment.new(
50
19
  'ENV' => 'set_from_ENV',
51
20
  )
52
- assert_equal 'set_from_ENV', env.environment
21
+ assert_equal('set_from_ENV', env.environment)
53
22
  end
54
23
 
55
24
  def test_environment_uses_rails_env_when_rails_is_available
56
25
  Rails.stubs(:env).returns('production')
57
- assert_equal 'production', StatsD::Instrument::Environment.environment
26
+ assert_equal('production', StatsD::Instrument::Environment.environment)
58
27
  end
59
28
 
60
29
  def test_environment_defaults_to_development
61
30
  env = StatsD::Instrument::Environment.new({})
62
- assert_equal 'development', env.environment
31
+ assert_equal('development', env.environment)
63
32
  end
64
33
 
65
- def test_legacy_client_is_default_client
34
+ def test_client_returns_client_instance
66
35
  env = StatsD::Instrument::Environment.new({})
67
- assert_kind_of StatsD::Instrument::LegacyClient, env.client
68
- end
69
-
70
- def test_client_returns_new_client_if_environment_asks_for_it
71
- env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1')
72
- assert_kind_of StatsD::Instrument::Client, env.client
36
+ assert_kind_of(StatsD::Instrument::Client, env.client)
73
37
  end
74
38
 
75
39
  def test_client_from_env_uses_log_sink_in_development_environment
76
40
  env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1', 'STATSD_ENV' => 'development')
77
- assert_kind_of StatsD::Instrument::LogSink, env.client.sink
41
+ assert_kind_of(StatsD::Instrument::LogSink, env.client.sink)
78
42
  end
79
43
 
80
44
  def test_client_from_env_uses_null_sink_in_test_environment
81
45
  env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1', 'STATSD_ENV' => 'test')
82
- assert_kind_of StatsD::Instrument::NullSink, env.client.sink
46
+ assert_kind_of(StatsD::Instrument::NullSink, env.client.sink)
83
47
  end
84
48
 
85
49
  def test_client_from_env_uses_udp_sink_in_staging_environment
86
50
  env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1', 'STATSD_ENV' => 'staging')
87
- assert_kind_of StatsD::Instrument::UDPSink, env.client.sink
51
+ assert_kind_of(StatsD::Instrument::UDPSink, env.client.sink)
88
52
  end
89
53
 
90
54
  def test_client_from_env_uses_udp_sink_in_production_environment
91
55
  env = StatsD::Instrument::Environment.new('STATSD_USE_NEW_CLIENT' => '1', 'STATSD_ENV' => 'production')
92
- assert_kind_of StatsD::Instrument::UDPSink, env.client.sink
56
+ assert_kind_of(StatsD::Instrument::UDPSink, env.client.sink)
93
57
  end
94
58
  end
@@ -1,25 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rubocop'
4
+ require 'rubocop/cop/legacy/corrector'
4
5
 
5
6
  module RubocopHelper
6
7
  attr_accessor :cop
7
8
 
8
9
  private
9
10
 
11
+ RUBY_VERSION = 2.5
12
+ private_constant :RUBY_VERSION
13
+
10
14
  def assert_no_offenses(source)
11
- investigate(RuboCop::ProcessedSource.new(source, 2.3, nil))
12
- assert_predicate cop.offenses, :empty?, "Did not expect Rubocop to find offenses"
15
+ investigate(RuboCop::ProcessedSource.new(source, RUBY_VERSION, nil))
16
+ assert_predicate(cop.offenses, :empty?, "Did not expect Rubocop to find offenses")
13
17
  end
14
18
 
15
19
  def assert_offense(source)
16
- investigate(RuboCop::ProcessedSource.new(source, 2.3, nil))
17
- refute_predicate cop.offenses, :empty?, "Expected Rubocop to find offenses"
20
+ investigate(RuboCop::ProcessedSource.new(source, RUBY_VERSION, nil))
21
+ refute_predicate(cop.offenses, :empty?, "Expected Rubocop to find offenses")
18
22
  end
19
23
 
20
24
  def assert_no_autocorrect(source)
21
25
  corrected = autocorrect_source(source)
22
- assert_equal source, corrected
26
+ assert_equal(source, corrected)
23
27
  end
24
28
 
25
29
  def autocorrect_source(source)
@@ -27,16 +31,15 @@ module RubocopHelper
27
31
  RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
28
32
  cop.instance_variable_get(:@options)[:auto_correct] = true
29
33
 
30
- processed_source = RuboCop::ProcessedSource.new(source, 2.3, nil)
34
+ processed_source = RuboCop::ProcessedSource.new(source, RUBY_VERSION, nil)
31
35
  investigate(processed_source)
32
36
 
33
- corrector = RuboCop::Cop::Corrector.new(processed_source.buffer, cop.corrections)
37
+ corrector = RuboCop::Cop::Legacy::Corrector.new(processed_source.buffer, cop.corrections)
34
38
  corrector.rewrite
35
39
  end
36
40
 
37
41
  def investigate(processed_source)
38
42
  forces = RuboCop::Cop::Force.all.each_with_object([]) do |klass, instances|
39
- next unless cop.join_force?(klass)
40
43
  instances << klass.new([cop])
41
44
  end
42
45
 
@@ -17,10 +17,10 @@ class HelpersTest < Minitest::Test
17
17
  end
18
18
  StatsD.gauge('gauge', 15)
19
19
 
20
- assert_equal 2, metrics.length
21
- assert_equal 'counter', metrics[0].name
22
- assert_equal 'gauge', metrics[1].name
23
- assert_equal 12, metrics[1].value
20
+ assert_equal(2, metrics.length)
21
+ assert_equal('counter', metrics[0].name)
22
+ assert_equal('gauge', metrics[1].name)
23
+ assert_equal(12, metrics[1].value)
24
24
  end
25
25
 
26
26
  def test_capture_metrics_with_new_client
@@ -34,7 +34,7 @@ class HelpersTest < Minitest::Test
34
34
  end
35
35
  StatsD.gauge('gauge', 15)
36
36
 
37
- assert_equal 2, metrics.length
37
+ assert_equal(2, metrics.length)
38
38
 
39
39
  ensure
40
40
  StatsD.singleton_client = @old_client
@@ -6,39 +6,24 @@ class IntegrationTest < Minitest::Test
6
6
  def setup
7
7
  @server = UDPSocket.new
8
8
  @server.bind('localhost', 0)
9
- port = @server.addr[1]
10
9
 
11
- @old_backend = StatsD.backend
12
- StatsD.backend = StatsD::Instrument::Backends::UDPBackend.new("localhost:#{port}")
10
+ @env = StatsD::Instrument::Environment.new(
11
+ 'STATSD_ADDR' => "#{@server.addr[2]}:#{@server.addr[1]}",
12
+ 'STATSD_IMPLEMENTATION' => 'dogstatsd',
13
+ 'STATSD_ENV' => 'production',
14
+ )
15
+
16
+ @old_client = StatsD.singleton_client
17
+ StatsD.singleton_client = @env.client
13
18
  end
14
19
 
15
20
  def teardown
21
+ StatsD.singleton_client = @old_client
16
22
  @server.close
17
- StatsD.backend = @old_backend
18
23
  end
19
24
 
20
25
  def test_live_local_udp_socket
21
26
  StatsD.increment('counter')
22
- assert_equal "counter:1|c", @server.recvfrom(100).first
23
- end
24
-
25
- def test_synchronize_in_exit_handler_handles_thread_error_and_exits_cleanly
26
- pid = fork do
27
- Signal.trap('TERM') do
28
- StatsD.increment('exiting')
29
- Process.exit!(0)
30
- end
31
-
32
- sleep 100
33
- end
34
-
35
- Process.kill('TERM', pid)
36
- _, exit_status = Process.waitpid2(pid)
37
-
38
- assert_equal 0, exit_status, "The forked process did not exit cleanly"
39
- assert_equal "exiting:1|c", @server.recvfrom_nonblock(100).first
40
-
41
- rescue NotImplementedError
42
- pass("Fork is not implemented on #{RUBY_PLATFORM}")
27
+ assert_equal("counter:1|c", @server.recvfrom(100).first)
43
28
  end
44
29
  end