1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
require_relative 'helper'
require 'tempfile'
require 'socket'
require 'webrick'
require 'open-uri'
require 'net/http'
require 'net/https'
begin
require 'stackprof'
require 'tmpdir'
rescue LoadError
else
test_profile = true
end
describe Camping::Server do
argv = Camping::Server::ARGV = []
define_method(:argv) { argv }
before {
argv.clear
@original_dir = Dir.pwd
Dir.chdir "test/integration"
}
after {
Dir.chdir @original_dir
}
# Probably need to revise this for the camping port
def app
lambda { |env| [200, { 'content-type' => 'text/plain' }, ['success']] }
end
# learn what this is doing.
def with_stderr
old, $stderr = $stderr, StringIO.new
yield $stderr
ensure
$stderr = old
end
# first copied test to make sure this works right.
it "overrides :config if :app is passed in" do
server = Rackup::Server.new(app: "FOO")
server.app.must_equal "FOO"
end
# Fails a lot
# it "runs a server" do
# pidfile = Tempfile.open('pidfile') { |f| break f }
# FileUtils.rm pidfile.path
# server = Camping::Server.new(
# app: "FOO",
# environment: 'none',
# pid: pidfile.path,
# Port: TCPServer.open('localhost', '0'){|s| s.addr[1] },
# Host: 'localhost',
# Logger: WEBrick::Log.new(nil, WEBrick::BasicLog::WARN),
# AccessLog: [],
# daemonize: false,
# server: 'webrick'
# )
# t = Thread.new { server.start { |s| Thread.current[:server] = s } }
# t.join(0.01) until t[:server] && t[:server].status != :Stop
# body = if URI.respond_to?(:open)
# URI.open("http://localhost:#{server.options[:Port]}/") { |f| f.read }
# else
# open("http://localhost:#{server.options[:Port]}/") { |f| f.read }
# end
# body.must_include 'Let's go Camping'
# Process.kill(:INT, $$)
# t.join
# open(pidfile.path) { |f| f.read.must_equal $$.to_s }
# end
it "Loads the kindling initializers" do
pidfile = Tempfile.open('pidfile') { |f| break f }
FileUtils.rm pidfile.path
server = Camping::Server.new
starty_file = false
starty_name = "Starty"
t = Thread.new {
server.start { |s|
Thread.current[:server] = s
starty_file = Object.constants.include? :Starty
starty_name = Starty.name
}
}
t.join(0.01) until t[:server] && t[:server].status != :Stop
starty_file.must_equal true
starty_name.must_equal "Starty"
Process.kill(:INT, $$)
t.join
end
end
|