-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AMS Benchmark tests #832 #872
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ source 'https://rubygems.org' | |
# Specify your gem's dependencies in active_model_serializers.gemspec | ||
gemspec | ||
|
||
gem "minitest" | ||
gem 'minitest' | ||
gem 'git' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you should use the gemspec's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😅 yeap |
||
|
||
version = ENV["RAILS_VERSION"] || "4.2" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,46 @@ | ||
require "bundler/gem_tasks" | ||
|
||
require 'bundler/gem_tasks' | ||
require 'git' | ||
require 'benchmark' | ||
require 'rake/testtask' | ||
|
||
task :default => :test | ||
|
||
Rake::TestTask.new do |t| | ||
t.libs << "test" | ||
t.test_files = FileList['test/**/*_test.rb'] | ||
t.ruby_opts = ['-r./test/test_helper.rb'] | ||
t.verbose = true | ||
end | ||
|
||
task :default => :test | ||
Rake::TestTask.new :benchmark_tests do |t| | ||
t.libs << "test" | ||
t.test_files = FileList['test/**/*_benchmark.rb'] | ||
t.ruby_opts = ['-r./test/test_helper.rb'] | ||
t.verbose = true | ||
end | ||
|
||
task :benchmark do | ||
@git = Git.init('.') | ||
ref = @git.current_branch | ||
|
||
actual = run_benchmark_spec ref | ||
master = run_benchmark_spec 'master' | ||
|
||
@git.checkout(ref) | ||
|
||
puts "\n\nResults ============================\n" | ||
puts "------------------------------------~> (Branch) MASTER" | ||
puts master | ||
puts "------------------------------------\n\n" | ||
|
||
puts "------------------------------------~> (Actual Branch) #{ref}" | ||
puts actual | ||
puts "------------------------------------" | ||
end | ||
|
||
def run_benchmark_spec(ref) | ||
@git.checkout(ref) | ||
response = Benchmark.realtime { Rake::Task['benchmark_tests'].invoke } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, when you switch to a branch, do you run the tests only once? Given there's warm up and all that, would it make sense to run it 2 or 3 times each branch in order to get a better average? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made some tests and there was no huge difference, anyway, I'll give it a try again after made the updates required 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. Just remember that tests are usually very fast, but when in production and getting hit by thousands of users, the minor difference can make a huge difference. |
||
Rake::Task['benchmark_tests'].reenable | ||
response | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'test_helper' | ||
|
||
module ActionController | ||
module Serialization | ||
class SerializerTest < ActionController::TestCase | ||
class PostController < ActionController::Base | ||
|
||
def render_with_cache_enable | ||
comment = Comment.new({ id: 1, body: 'ZOMG A COMMENT' }) | ||
author = Author.new(id: 1, name: 'Joao Moura.') | ||
post = Post.new({ id: 1, title: 'New Post', blog:nil, body: 'Body', comments: [comment], author: author }) | ||
|
||
render json: post | ||
end | ||
end | ||
|
||
tests PostController | ||
|
||
def test_render_with_cache_enable | ||
ActionController::Base.cache_store.clear | ||
get :render_with_cache_enable | ||
|
||
expected = { | ||
id: 1, | ||
title: 'New Post', | ||
body: 'Body', | ||
comments: [ | ||
{ | ||
id: 1, | ||
body: 'ZOMG A COMMENT' } | ||
], | ||
blog: { | ||
id: 999, | ||
name: 'Custom blog' | ||
}, | ||
author: { | ||
id: 1, | ||
name: 'Joao Moura.' | ||
} | ||
} | ||
|
||
assert_equal 'application/json', @response.content_type | ||
assert_equal expected.to_json, @response.body | ||
|
||
get :render_with_cache_enable | ||
assert_equal expected.to_json, @response.body | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
housekeeping: I don't think is a good idea to set JRUBY_OPTS this way since travis uses
JRUBY_OPTS="--server -Dcext.enabled=false -Xcompile.invokedynamic=false"
now (cext.enabled=false is the future) and ref: rspec/rspec-dev#115There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joaomdmoura ^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😢
I'll find a workaround