mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
AMS Benchmark tests #832
Adding a benchmak test structure to help contributors to keep track of how their PR will impact overall performance. It enables developers to create test inside of tests/benchmark. This implementation adds a rake task: ```rake benchmark``` that checkout one commit before, run the test of tests/benchmark, then mover back to the last commit and run it again. By comparing the benchmark results between both commits the contributor will notice if and how much his contribution will impact overall performance.
This commit is contained in:
parent
31a30c8214
commit
952ab0438f
1
Gemfile
1
Gemfile
@ -45,4 +45,5 @@ end
|
|||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem 'rubocop', '~> 0.36', require: false
|
gem 'rubocop', '~> 0.36', require: false
|
||||||
|
gem 'git'
|
||||||
end
|
end
|
||||||
|
|||||||
35
Rakefile
35
Rakefile
@ -74,3 +74,38 @@ end
|
|||||||
|
|
||||||
desc 'CI test task'
|
desc 'CI test task'
|
||||||
task :ci => [:default]
|
task :ci => [:default]
|
||||||
|
|
||||||
|
require 'git'
|
||||||
|
require 'benchmark'
|
||||||
|
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 }
|
||||||
|
Rake::Task['benchmark_tests'].reenable
|
||||||
|
response
|
||||||
|
end
|
||||||
|
|||||||
50
test/benchmark/serialization_benchmark.rb
Normal file
50
test/benchmark/serialization_benchmark.rb
Normal file
@ -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
|
||||||
Loading…
Reference in New Issue
Block a user