Skip to content

Commit

Permalink
Remove monolithic minitest tests and setup CI
Browse files Browse the repository at this point in the history
  • Loading branch information
kbogtob committed Mar 23, 2020
1 parent 41291ec commit f698c8d
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 1,360 deletions.
14 changes: 8 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ require 'bundler/gem_tasks'
require 'rake/testtask'
require 'yard'

task default: [:test, :rubocop]
task default: [:spec, :rubocop]

Rake::TestTask.new(:test) do |test|
test.loader = :direct
test.pattern = './test/statsd_spec.rb'
test.verbose = true
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
# rubocop:disable Lint/HandleExceptions
rescue LoadError
# rubocop:enable Lint/HandleExceptions
end

namespace :build do
YARD::Rake::YardocTask.new :doc
end

task :rubocop do
sh "rubocop"
sh 'rubocop'
end
28 changes: 24 additions & 4 deletions spec/integrations/allocation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,26 @@
subject.increment('foobar')
end

let(:expected_allocations) do
if RUBY_VERSION < '2.4.0'
22
elsif RUBY_VERSION >= '2.4.0' && RUBY_VERSION < '2.5.0'
19
else
18
end
end

it 'produces low amounts of garbage for increment' do
expect do
subject.increment('foobar')
end.to make_allocations(18)
end.to make_allocations(expected_allocations)
end

it 'produces low amounts of garbage for timing' do
expect do
subject.time('foobar') { 1111 }
end.to make_allocations(18)
end.to make_allocations(expected_allocations)
end

context 'without telemetry' do
Expand All @@ -59,16 +69,26 @@
)
end

let(:expected_allocations) do
if RUBY_VERSION < '2.4.0'
11
elsif RUBY_VERSION >= '2.4.0' && RUBY_VERSION < '2.5.0'
9
else
8
end
end

it 'produces even lower amounts of garbage for increment' do
expect do
subject.increment('foobar')
end.to make_allocations(8)
end.to make_allocations(expected_allocations)
end

it 'produces even lower amounts of garbage for time' do
expect do
subject.time('foobar') { 1111 }
end.to make_allocations(8)
end.to make_allocations(expected_allocations)
end
end
end
4 changes: 4 additions & 0 deletions spec/integrations/connection_edge_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@
end

context 'when the socket is full (drop strategy)' do
before do
skip if RUBY_VERSION < '2.3.0'
end

before do
allow(fake_socket)
.to receive(:sendmsg_nonblock)
Expand Down
2 changes: 1 addition & 1 deletion spec/matchers/make_allocations_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@allocations == expected
end

failure_message do |actual|
failure_message do |_|
"expected that block would make #{expected} allocations but made #{@allocations}"
end
end
4 changes: 2 additions & 2 deletions spec/shared/taggable_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
it 'merges global and provided tags' do
basic_action

expect(socket.recv[0]).to match /^#{normal_expected_result}|#global_tag,country:usa,state:ny,other/
expect(socket.recv[0]).to match(/^#{normal_expected_result}|#global_tag,country:usa,state:ny,other/)
end
end
end
Expand All @@ -48,7 +48,7 @@
it 'merges global and provided tags' do
basic_action

expect(socket.recv[0]).to match /^#{normal_expected_result}|#global_tag,country:usa,state:ny/
expect(socket.recv[0]).to match(/^#{normal_expected_result}|#global_tag,country:usa,state:ny/)
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions spec/statsd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@
it 'ensures the statsd instance is closed' do
expect(fake_statsd).to receive(:close)

# rubocop:disable Lint/RescueWithoutErrorClass
described_class.open do
raise 'stop'
end rescue nil
# rubocop:enable Lint/RescueWithoutErrorClass
end
end

Expand Down Expand Up @@ -498,7 +500,7 @@

before do
Timecop.freeze(before_date)
allow(Process).to receive(:clock_gettime).and_return(0, 1)
allow(Process).to receive(:clock_gettime).and_return(0, 1) if Datadog::Statsd::PROCESS_TIME_SUPPORTED
end

it_behaves_like 'a metrics method', 'foobar:1000|ms' do
Expand All @@ -519,10 +521,12 @@
end

it 'ensures the timing is sent' do
# rubocop:disable Lint/RescueWithoutErrorClass
subject.time('foobar') do
Timecop.travel(after_date)
raise 'stop'
end rescue nil
# rubocop:enable Lint/RescueWithoutErrorClass

expect(socket.recv[0]).to eq_with_telemetry 'foobar:1000|ms'
end
Expand Down Expand Up @@ -834,7 +838,6 @@ def subject.telemetry

it 'flushes when the buffer gets too big' do
expected_message = 'mycounter:1|c'
previous_payload_length = 0

subject.batch do |s|
# increment a counter to fill the buffer and trigger buffer flush
Expand Down
87 changes: 0 additions & 87 deletions test/helper.rb

This file was deleted.

Loading

0 comments on commit f698c8d

Please sign in to comment.