提交 0acd4a57 编写于 作者: E eileencodes

Skip url_helpers instead of caching, speed up integration tests

We shouldn't cache if it's not absolutely necessary. Removes
route caching and instead skips using the `url_helpers` is the
integration test session doesn't require it. Benchmark ips on
integration and controller index method tests below.

Without any caching or changes to `#url_helpers`:
```
Calculating -------------------------------------
INDEX: Integration Test
                        71.000  i/100ms
INDEX: Functional Test
                        99.000  i/100ms
-------------------------------------------------
INDEX: Integration Test
                        728.878  (± 8.0%) i/s -      3.692k
INDEX: Functional Test
                          1.015k (± 6.7%) i/s -      5.148k

Comparison:
INDEX: Functional Test:     1015.4 i/s
INDEX: Integration Test:      728.9 i/s - 1.39x slower
```

With caching on `#url_helpers`:
```
Calculating -------------------------------------
INDEX: Integration Test
                        74.000  i/100ms
INDEX: Functional Test
                        99.000  i/100ms
-------------------------------------------------
INDEX: Integration Test
                        752.377  (± 6.9%) i/s -      3.774k
INDEX: Functional Test
                          1.021k (± 6.7%) i/s -      5.148k

Comparison:
INDEX: Functional Test:     1021.1 i/s
INDEX: Integration Test:      752.4 i/s - 1.36x slower
```

Afer removing the caching and bypassing the `url_helpers` when not
necessary in the session:
```
Calculating -------------------------------------
INDEX: Integration Test
                        87.000  i/100ms
INDEX: Functional Test
                        97.000  i/100ms
-------------------------------------------------
INDEX: Integration Test
                        828.433  (± 6.4%) i/s -      4.176k
INDEX: Functional Test
                        926.763  (± 7.2%) i/s -      4.656k

Comparison:
INDEX: Functional Test:      926.8 i/s
INDEX: Integration Test:      828.4 i/s - 1.12x slower
```
上级 ce32ff46
...@@ -409,14 +409,6 @@ def #{name} ...@@ -409,14 +409,6 @@ def #{name}
end end
def url_helpers(supports_path = true) def url_helpers(supports_path = true)
if supports_path
@url_helpers_with_paths ||= generate_url_helpers(supports_path)
else
@url_helpers_without_paths ||= generate_url_helpers(supports_path)
end
end
def generate_url_helpers(supports_path)
routes = self routes = self
Module.new do Module.new do
......
...@@ -222,15 +222,6 @@ def initialize(app) ...@@ -222,15 +222,6 @@ def initialize(app)
super() super()
@app = app @app = app
# If the app is a Rails app, make url_helpers available on the session
# This makes app.url_for and app.foo_path available in the console
if app.respond_to?(:routes)
singleton_class.class_eval do
include app.routes.url_helpers
include app.routes.mounted_helpers
end
end
reset! reset!
end end
...@@ -396,6 +387,8 @@ def build_full_uri(path, env) ...@@ -396,6 +387,8 @@ def build_full_uri(path, env)
module Runner module Runner
include ActionDispatch::Assertions include ActionDispatch::Assertions
APP_SESSIONS = {}
def app def app
@app ||= nil @app ||= nil
end end
...@@ -403,7 +396,19 @@ def app ...@@ -403,7 +396,19 @@ def app
# Reset the current session. This is useful for testing multiple sessions # Reset the current session. This is useful for testing multiple sessions
# in a single test case. # in a single test case.
def reset! def reset!
@integration_session = Integration::Session.new(app) @integration_session = create_session(app)
end
def create_session(app)
klass = APP_SESSIONS[app] ||= Class.new(Integration::Session) {
# If the app is a Rails app, make url_helpers available on the session
# This makes app.url_for and app.foo_path available in the console
if app.respond_to?(:routes)
include app.routes.url_helpers
include app.routes.mounted_helpers
end
}
klass.new(app)
end end
def remove! # :nodoc: def remove! # :nodoc:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册