Skip to content

Commit 6196eb5

Browse files
committed
Refactor flaky specs skip
- define FLAKY_ENV const instead of flaky_env? helper - use `:flaky` tag on examples to mark that it should be excluded on `FLAKY_ENV`, instead of `skip "..." if FLAKY_ENV` - do not run tests coverage analysis on FLAKY_ENV
1 parent e36f552 commit 6196eb5

File tree

2 files changed

+23
-36
lines changed

2 files changed

+23
-36
lines changed

spec/spec_helper.rb

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
# frozen_string_literal: true
2-
# coding: utf-8
32

4-
require "simplecov"
5-
require "coveralls"
3+
# Are we in a flaky environment?
4+
FLAKY_ENV = defined?(JRUBY_VERSION) && ENV["CI"]
5+
6+
unless FLAKY_ENV
7+
require "simplecov"
8+
require "coveralls"
69

7-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
8-
[
9-
SimpleCov::Formatter::HTMLFormatter,
10-
Coveralls::SimpleCov::Formatter
11-
]
12-
)
10+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
11+
[
12+
SimpleCov::Formatter::HTMLFormatter,
13+
Coveralls::SimpleCov::Formatter
14+
]
15+
)
1316

14-
SimpleCov.start do
15-
add_filter "/spec/"
16-
minimum_coverage 80
17+
SimpleCov.start do
18+
add_filter "/spec/"
19+
minimum_coverage 80
20+
end
1721
end
1822

1923
require "http"
2024
require "rspec/its"
2125
require "support/capture_warning"
2226

23-
# Are we in a flaky environment?
24-
def flaky_env?
25-
defined?(JRUBY_VERSION) && ENV["CI"]
26-
end
27-
2827
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
2928
RSpec.configure do |config|
3029
config.expect_with :rspec do |expectations|
@@ -50,6 +49,7 @@ def flaky_env?
5049
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
5150
# get run.
5251
config.filter_run :focus
52+
config.filter_run_excluding :flaky if FLAKY_ENV
5353
config.run_all_when_everything_filtered = true
5454

5555
# Limits the available syntax to the non-monkey patched syntax that is recommended.

spec/support/http_handling_shared.rb

+6-19
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,15 @@
5050
context "of 0" do
5151
let(:read_timeout) { 0 }
5252

53-
it "times out" do
54-
skip "flaky environment" if flaky_env?
53+
it "times out", :flaky do
5554
expect { response }.to raise_error(HTTP::TimeoutError, /Read/i)
5655
end
5756
end
5857

5958
context "of 2.5" do
6059
let(:read_timeout) { 2.5 }
6160

62-
it "does not time out" do
63-
# TODO: investigate sporadic JRuby timeouts on CI
64-
skip "flaky environment" if flaky_env?
65-
61+
it "does not time out", :flaky do
6662
expect { client.get("#{server.endpoint}/sleep").body.to_s }.to_not raise_error
6763
end
6864
end
@@ -96,10 +92,7 @@
9692

9793
let(:read_timeout) { 2.5 }
9894

99-
it "does not timeout" do
100-
# TODO: investigate sporadic JRuby timeouts on CI
101-
skip "flaky environment" if flaky_env?
102-
95+
it "does not timeout", :flaky do
10396
client.get("#{server.endpoint}/sleep").body.to_s
10497
client.get("#{server.endpoint}/sleep").body.to_s
10598
end
@@ -130,9 +123,7 @@
130123
end
131124

132125
context "on a mixed state" do
133-
it "re-opens the connection" do
134-
skip "flaky environment" if flaky_env?
135-
126+
it "re-opens the connection", :flaky do
136127
first_socket_id = client.get("#{server.endpoint}/socket/1").body.to_s
137128

138129
client.instance_variable_set(:@state, :dirty)
@@ -163,9 +154,7 @@
163154
end
164155

165156
context "with a socket issue" do
166-
it "transparently reopens" do
167-
skip "flaky environment" if flaky_env?
168-
157+
it "transparently reopens", :flaky do
169158
first_socket_id = client.get("#{server.endpoint}/socket").body.to_s
170159
expect(first_socket_id).to_not eq("")
171160
# Kill off the sockets we used
@@ -195,9 +184,7 @@
195184
context "when disabled" do
196185
let(:options) { {} }
197186

198-
it "opens new sockets" do
199-
skip "flaky environment" if flaky_env?
200-
187+
it "opens new sockets", :flaky do
201188
expect(sockets_used).to_not include("")
202189
expect(sockets_used.uniq.length).to eq(2)
203190
end

0 commit comments

Comments
 (0)