Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
heroku-buildpack-static
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Python-Dev
heroku-buildpack-static
Commits
47e8f6de
Commit
47e8f6de
authored
Jul 16, 2015
by
Terence Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
speed up test runs by only booting docker once in a run block per test case
parent
ac036e0c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
68 deletions
+88
-68
simple_spec.rb
spec/simple_spec.rb
+65
-53
app_runner.rb
spec/support/app_runner.rb
+23
-15
No files found.
spec/simple_spec.rb
View file @
47e8f6de
...
@@ -59,17 +59,19 @@ RSpec.describe "Simple" do
...
@@ -59,17 +59,19 @@ RSpec.describe "Simple" do
let
(
:name
)
{
"routes"
}
let
(
:name
)
{
"routes"
}
it
"should support custom routes"
do
it
"should support custom routes"
do
response
=
app
.
get
(
"/foo.html"
)
app
.
run
do
expect
(
response
.
code
).
to
eq
(
"200"
)
response
=
app
.
get
(
"/foo.html"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"hello world"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"hello world"
)
response
=
app
.
get
(
"/route/foo"
)
response
=
app
.
get
(
"/route/foo"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"hello from route"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"hello from route"
)
response
=
app
.
get
(
"/route/foo/bar"
)
response
=
app
.
get
(
"/route/foo/bar"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"hello from route"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"hello from route"
)
end
end
end
end
end
...
@@ -158,30 +160,34 @@ STATIC_JSON
...
@@ -158,30 +160,34 @@ STATIC_JSON
let
(
:name
)
{
"custom_headers"
}
let
(
:name
)
{
"custom_headers"
}
it
"should return the respected headers only for the path specified"
do
it
"should return the respected headers only for the path specified"
do
response
=
app
.
get
(
"/"
)
app
.
run
do
expect
(
response
[
"cache-control"
]).
to
eq
(
"no-cache"
)
response
=
app
.
get
(
"/"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
[
"cache-control"
]).
to
eq
(
"no-cache"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"index"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"index"
)
response
=
app
.
get
(
"/foo.html"
)
response
=
app
.
get
(
"/foo.html"
)
expect
(
response
[
"cache-control"
]).
to
eq
(
nil
)
expect
(
response
[
"cache-control"
]).
to
eq
(
nil
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"foo"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"foo"
)
end
end
end
describe
"wildcard paths"
do
describe
"wildcard paths"
do
let
(
:name
)
{
"custom_headers_wildcard"
}
let
(
:name
)
{
"custom_headers_wildcard"
}
it
"should add the headers"
do
it
"should add the headers"
do
response
=
app
.
get
(
"/cache/"
)
app
.
run
do
expect
(
response
[
"Cache-Control"
]).
to
eq
(
"max-age=38400"
)
response
=
app
.
get
(
"/cache/"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
[
"Cache-Control"
]).
to
eq
(
"max-age=38400"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"cached index"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"cached index"
)
response
=
app
.
get
(
"/"
)
expect
(
response
[
"Cache-Control"
]).
to
eq
(
nil
)
response
=
app
.
get
(
"/"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
[
"Cache-Control"
]).
to
eq
(
nil
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"index"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"index"
)
end
end
end
end
end
...
@@ -199,15 +205,17 @@ STATIC_JSON
...
@@ -199,15 +205,17 @@ STATIC_JSON
let
(
:name
)
{
"custom_headers_clean_urls"
}
let
(
:name
)
{
"custom_headers_clean_urls"
}
it
"should add the headers"
do
it
"should add the headers"
do
response
=
app
.
get
(
"/foo"
)
app
.
run
do
expect
(
response
.
code
).
to
eq
(
"200"
)
response
=
app
.
get
(
"/foo"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"foo"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
[
"X-Header"
]).
to
eq
(
"present"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"foo"
)
expect
(
response
[
"X-Header"
]).
to
eq
(
"present"
)
response
=
app
.
get
(
"/bar"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
response
=
app
.
get
(
"/bar"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"bar"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
[
"X-Header"
]).
to
be_nil
expect
(
response
.
body
.
chomp
).
to
eq
(
"bar"
)
expect
(
response
[
"X-Header"
]).
to
be_nil
end
end
end
it
"should not add headers for .html urls"
do
it
"should not add headers for .html urls"
do
...
@@ -221,15 +229,17 @@ STATIC_JSON
...
@@ -221,15 +229,17 @@ STATIC_JSON
let
(
:name
)
{
"custom_headers_routes"
}
let
(
:name
)
{
"custom_headers_routes"
}
it
"should add headers"
do
it
"should add headers"
do
response
=
app
.
get
(
"/active"
)
app
.
run
do
expect
(
response
.
code
).
to
eq
(
"200"
)
response
=
app
.
get
(
"/active"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"index"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
[
"X-Header"
]).
to
eq
(
"present"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"index"
)
expect
(
response
[
"X-Header"
]).
to
eq
(
"present"
)
response
=
app
.
get
(
"/foo/foo.html"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
response
=
app
.
get
(
"/foo/foo.html"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"foo"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
[
"X-Header"
]).
to
be_nil
expect
(
response
.
body
.
chomp
).
to
eq
(
"foo"
)
expect
(
response
[
"X-Header"
]).
to
be_nil
end
end
end
end
end
...
@@ -269,15 +279,17 @@ STATIC_JSON
...
@@ -269,15 +279,17 @@ STATIC_JSON
end
end
it
"should proxy requests"
do
it
"should proxy requests"
do
response
=
app
.
get
(
"/api/bar/"
)
app
.
run
do
expect
(
response
.
code
).
to
eq
(
"200"
)
response
=
app
.
get
(
"/api/bar/"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"api"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
[
"X-Header"
]).
to
eq
(
"present"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"api"
)
expect
(
response
[
"X-Header"
]).
to
eq
(
"present"
)
response
=
app
.
get
(
"/api/baz/"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
response
=
app
.
get
(
"/api/baz/"
)
expect
(
response
.
body
.
chomp
).
to
eq
(
"baz"
)
expect
(
response
.
code
).
to
eq
(
"200"
)
expect
(
response
[
"X-Header"
]).
to
be_nil
expect
(
response
.
body
.
chomp
).
to
eq
(
"baz"
)
expect
(
response
[
"X-Header"
]).
to
be_nil
end
end
end
end
end
end
end
...
...
spec/support/app_runner.rb
View file @
47e8f6de
...
@@ -20,6 +20,7 @@ class AppRunner
...
@@ -20,6 +20,7 @@ class AppRunner
CONTAINER_PORT
=
"3000"
CONTAINER_PORT
=
"3000"
def
initialize
(
fixture
,
env
=
nil
,
debug
=
false
)
def
initialize
(
fixture
,
env
=
nil
,
debug
=
false
)
@run
=
false
@debug
=
debug
@debug
=
debug
@container
=
Docker
::
Container
.
create
(
@container
=
Docker
::
Container
.
create
(
'Image'
=>
BuildpackBuilder
::
TAG
,
'Image'
=>
BuildpackBuilder
::
TAG
,
...
@@ -39,7 +40,9 @@ class AppRunner
...
@@ -39,7 +40,9 @@ class AppRunner
end
end
def
run
def
run
latch
=
Concurrent
::
CountDownLatch
.
new
(
1
)
@run
=
true
retn
=
nil
latch
=
Concurrent
::
CountDownLatch
.
new
(
1
)
run_thread
=
Thread
.
new
{
run_thread
=
Thread
.
new
{
latch
.
wait
(
0.5
)
latch
.
wait
(
0.5
)
yield
(
@container
)
yield
(
@container
)
...
@@ -51,26 +54,20 @@ class AppRunner
...
@@ -51,26 +54,20 @@ class AppRunner
end
end
}
}
r
un_thread
.
join
r
etn
=
run_thread
.
value
@container
.
stop
@container
.
stop
container_thread
.
join
container_thread
.
join
@run
=
false
retn
end
end
def
get
(
path
,
max_retries
=
5
)
def
get
(
path
,
max_retries
=
5
)
response
=
nil
if
@run
response
=
get_retry
(
path
,
max_retries
)
run
do
else
network_retry
(
max_retries
)
do
run
{
get_retry
(
path
,
max_retries
)
}
uri
=
URI
(
"
#{
path
}
"
)
uri
.
host
=
HOST_IP
if
uri
.
host
.
nil?
uri
.
port
=
HOST_PORT
if
(
uri
.
host
==
HOST_IP
&&
uri
.
port
!=
HOST_PORT
)
||
uri
.
port
.
nil?
uri
.
scheme
=
"http"
if
uri
.
scheme
.
nil?
response
=
Net
::
HTTP
.
get_response
(
URI
(
uri
.
to_s
))
end
end
end
response
end
end
def
destroy
def
destroy
...
@@ -78,6 +75,17 @@ class AppRunner
...
@@ -78,6 +75,17 @@ class AppRunner
end
end
private
private
def
get_retry
(
path
,
max_retries
)
network_retry
(
max_retries
)
do
uri
=
URI
(
"
#{
path
}
"
)
uri
.
host
=
HOST_IP
if
uri
.
host
.
nil?
uri
.
port
=
HOST_PORT
if
(
uri
.
host
==
HOST_IP
&&
uri
.
port
!=
HOST_PORT
)
||
uri
.
port
.
nil?
uri
.
scheme
=
"http"
if
uri
.
scheme
.
nil?
Net
::
HTTP
.
get_response
(
URI
(
uri
.
to_s
))
end
end
def
network_retry
(
max_retries
,
retry_count
=
0
)
def
network_retry
(
max_retries
,
retry_count
=
0
)
yield
yield
rescue
Errno
::
ECONNRESET
,
EOFError
rescue
Errno
::
ECONNRESET
,
EOFError
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment