-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
113 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# encoding: UTF-8 | ||
|
||
require 'rack/test' | ||
require 'rack' | ||
require 'prometheus/middleware/collector' | ||
require 'prometheus/middleware/exporter' | ||
|
||
API = Rack::Builder.new do | ||
use Rack::Deflater | ||
use Prometheus::Middleware::Collector | ||
use Prometheus::Middleware::Exporter | ||
|
||
map "/" do | ||
run ->(_) { [200, {'Content-Type' => 'text/html'}, ['OK']] } | ||
end | ||
end | ||
|
||
describe API do | ||
include Rack::Test::Methods | ||
|
||
let(:app) { described_class } | ||
|
||
context 'GET /metrics' do | ||
it 'fails on the second request' do | ||
get '/metrics' | ||
expect { last_response }.not_to raise_error | ||
expect { get '/metrics' }.not_to raise_error | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# encoding: UTF-8 | ||
|
||
require 'rack/test' | ||
require 'rack' | ||
require 'prometheus/middleware/collector' | ||
require 'prometheus/middleware/exporter' | ||
require "concurrent" | ||
|
||
API = Rack::Builder.new do | ||
use Rack::Deflater | ||
use Prometheus::Middleware::Collector | ||
use Prometheus::Middleware::Exporter | ||
|
||
map "/" do | ||
run ->(_) { [200, {'Content-Type' => 'text/html'}, ['OK']] } | ||
end | ||
end | ||
|
||
describe API do | ||
include Rack::Test::Methods | ||
|
||
let(:app) { described_class } | ||
|
||
context 'GET /metrics' do | ||
it "fails when it's multi threaded request" do | ||
latch = Concurrent::CountDownLatch.new(1) | ||
|
||
t1 = Thread.new do | ||
latch.wait | ||
get '/metrics' | ||
end | ||
|
||
t2 = Thread.new do | ||
latch.wait | ||
|
||
get '/metrics' | ||
end | ||
|
||
t3 = Thread.new do | ||
latch.wait | ||
|
||
get '/metrics' | ||
end | ||
|
||
latch.count_down | ||
|
||
[t1, t2, t3].each(&:join) | ||
|
||
expect { last_response }.not_to raise_error | ||
end | ||
end | ||
end |