Commit d70f6135 authored by Terence Lee's avatar Terence Lee

debug option for more nginx logs

parent 47e8f6de
......@@ -20,6 +20,7 @@ class NginxConfig
json["routes"] = Hash[json["routes"].map {|route, target| [NginxConfigUtil.to_regex(route), target] }]
json["redirects"] ||= {}
json["error_page"] ||= nil
json["debug"] ||= ENV['STATIC_DEBUG']
json.each do |key, value|
self.class.send(:define_method, key) { value }
end
......
......@@ -18,7 +18,12 @@ http {
server_tokens off;
access_log logs/access.log;
<% if debug %>
error_log stderr debug;
rewrite_log on;
<% else %>
error_log stderr;
<% end %>
include mime.types;
default_type application/octet-stream;
......
......@@ -293,4 +293,25 @@ STATIC_JSON
end
end
end
describe "debug" do
let(:name) { "debug" }
context "when debug is set" do
it "should display debug info" do
_, io_stream = app.get("/", true)
expect(io_stream.string).to include("[info]")
end
end
context "when debug isn't set" do
let(:name) { "hello_world" }
it "should not display debug info" do
skip if @debug
_, io_stream = app.get("/", true)
expect(io_stream.string).not_to include("[info]")
end
end
end
end
......@@ -22,6 +22,7 @@ class AppRunner
def initialize(fixture, env = nil, debug = false)
@run = false
@debug = debug
env.merge!("STATIC_DEBUG" => true) if @debug
@container = Docker::Container.create(
'Image' => BuildpackBuilder::TAG,
'Cmd' => ["bash", "-c", "cp -rf /src/* /app/ && /app/bin/boot"],
......@@ -39,17 +40,20 @@ class AppRunner
)
end
def run
def run(capture_io = false)
@run = true
retn = nil
latch = Concurrent::CountDownLatch.new(1)
io_stream = StringIO.new
run_thread = Thread.new {
latch.wait(0.5)
yield(@container)
}
container_thread = Thread.new {
@container.tap(&:start).attach do |stream, chunk|
puts "#{stream}: #{chunk}" if @debug
io_message = "#{stream}: #{chunk}"
puts io_message if @debug
io_stream << io_message if capture_io
latch.count_down if chunk.include?("Starting nginx...")
end
}
......@@ -57,16 +61,21 @@ class AppRunner
retn = run_thread.value
@container.stop
container_thread.join
io_stream.close_write
@run = false
retn
if capture_io
[retn, io_stream]
else
retn
end
end
def get(path, max_retries = 5)
def get(path, capture_io = false, max_retries = 5)
if @run
response = get_retry(path, max_retries)
get_retry(path, max_retries)
else
run { get_retry(path, max_retries) }
run(capture_io) { get_retry(path, max_retries) }
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment