mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Rename dummy to benchmark
This commit is contained in:
parent
821dcda700
commit
666756f779
@ -15,7 +15,7 @@ require 'English'
|
||||
|
||||
class BenchmarkDriver
|
||||
ROOT = Pathname File.expand_path(File.join('..', '..'), __FILE__)
|
||||
BASE = ENV.fetch('BASE') { ROOT.join('test', 'dummy') }
|
||||
BASE = ENV.fetch('BASE') { ROOT.join('test', 'benchmark') }
|
||||
ESCAPED_BASE = Shellwords.shellescape(BASE)
|
||||
|
||||
def self.benchmark(options)
|
||||
|
||||
@ -4,18 +4,18 @@ set -e
|
||||
case "$1" in
|
||||
|
||||
start)
|
||||
config="${CONFIG_RU:-test/dummy/config.ru}"
|
||||
bundle exec ruby -Ilib -S rackup "$config" --daemonize --pid tmp/dummy_app.pid --warn --server webrick
|
||||
until [ -f 'tmp/dummy_app.pid' ]; do
|
||||
config="${CONFIG_RU:-test/benchmark/config.ru}"
|
||||
bundle exec ruby -Ilib -S rackup "$config" --daemonize --pid tmp/benchmark_app.pid --warn --server webrick
|
||||
until [ -f 'tmp/benchmark_app.pid' ]; do
|
||||
sleep 0.1 # give it time to start.. I don't know a better way
|
||||
done
|
||||
cat tmp/dummy_app.pid
|
||||
cat tmp/benchmark_app.pid
|
||||
true
|
||||
;;
|
||||
|
||||
stop)
|
||||
if [ -f 'tmp/dummy_app.pid' ]; then
|
||||
kill -TERM $(cat tmp/dummy_app.pid)
|
||||
if [ -f 'tmp/benchmark_app.pid' ]; then
|
||||
kill -TERM $(cat tmp/benchmark_app.pid)
|
||||
else
|
||||
echo 'No pidfile'
|
||||
false
|
||||
@ -23,8 +23,8 @@ case "$1" in
|
||||
;;
|
||||
|
||||
status)
|
||||
if [ -f 'tmp/dummy_app.pid' ]; then
|
||||
kill -0 $(cat tmp/dummy_app.pid)
|
||||
if [ -f 'tmp/benchmark_app.pid' ]; then
|
||||
kill -0 $(cat tmp/benchmark_app.pid)
|
||||
[ "$?" -eq 0 ]
|
||||
else
|
||||
echo 'No pidfile'
|
||||
@ -18,7 +18,7 @@ class NullLogger < Logger
|
||||
def add(*_args, &_block)
|
||||
end
|
||||
end
|
||||
class DummyLogger < ActiveSupport::Logger
|
||||
class BenchmarkLogger < ActiveSupport::Logger
|
||||
def initialize
|
||||
@file = StringIO.new
|
||||
super(@file)
|
||||
@ -30,7 +30,7 @@ class DummyLogger < ActiveSupport::Logger
|
||||
end
|
||||
end
|
||||
# ref: https://gist.github.com/bf4/8744473
|
||||
class DummyApp < Rails::Application
|
||||
class BenchmarkApp < Rails::Application
|
||||
# Set up production configuration
|
||||
config.eager_load = true
|
||||
config.cache_classes = true
|
||||
@ -7,7 +7,7 @@ module Benchmark
|
||||
module ActiveModelSerializers
|
||||
module TestMethods
|
||||
def request(method, path)
|
||||
response = Rack::MockRequest.new(DummyApp).send(method, path)
|
||||
response = Rack::MockRequest.new(BenchmarkApp).send(method, path)
|
||||
if response.status.in?([404, 500])
|
||||
fail "omg, #{method}, #{path}, '#{response.status}', '#{response.body}'"
|
||||
end
|
||||
@ -35,7 +35,7 @@ class PostController < ActionController::Base
|
||||
ActionController::Base.cache_store.clear
|
||||
# Test caching is on
|
||||
# Uncomment to turn on logger; possible performance issue
|
||||
# logger = DummyLogger.new
|
||||
# logger = BenchmarkLogger.new
|
||||
# ActiveSupport::Cache::Store.logger = logger # seems to be the best way
|
||||
#
|
||||
# the below is used in some rails tests but isn't available/working in all versions, so far as I can tell
|
||||
@ -57,7 +57,7 @@ class PostController < ActionController::Base
|
||||
end
|
||||
|
||||
def cache_messages
|
||||
ActiveSupport::Cache::Store.logger.is_a?(DummyLogger) && ActiveSupport::Cache::Store.logger.messages.split("\n")
|
||||
ActiveSupport::Cache::Store.logger.is_a?(BenchmarkLogger) && ActiveSupport::Cache::Store.logger.messages.split("\n")
|
||||
end
|
||||
|
||||
def toggle_cache_status
|
||||
@ -104,7 +104,7 @@ else
|
||||
# ActiveModelSerializers::Model is a convenient
|
||||
# serializable class to inherit from when making
|
||||
# serializable non-activerecord objects.
|
||||
class DummyModel
|
||||
class BenchmarkModel
|
||||
include ActiveModel::Model
|
||||
include ActiveModel::Serializers::JSON
|
||||
|
||||
@ -139,19 +139,19 @@ else
|
||||
end
|
||||
end
|
||||
|
||||
class Comment < DummyModel
|
||||
class Comment < BenchmarkModel
|
||||
attr_accessor :id, :body
|
||||
end
|
||||
|
||||
class Author < DummyModel
|
||||
class Author < BenchmarkModel
|
||||
attr_accessor :id, :name, :posts
|
||||
end
|
||||
|
||||
class Post < DummyModel
|
||||
class Post < BenchmarkModel
|
||||
attr_accessor :id, :title, :body, :comments, :blog, :author
|
||||
end
|
||||
|
||||
class Blog < DummyModel
|
||||
class Blog < BenchmarkModel
|
||||
attr_accessor :id, :name
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user