Skip to content

Commit

Permalink
Merge pull request #5 from emancu/remove_test_server
Browse files Browse the repository at this point in the history
Remove test server and make tests run faster
  • Loading branch information
emancu committed Oct 5, 2013
2 parents de148c7 + 747a9a2 commit e8dd047
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 90 deletions.
5 changes: 4 additions & 1 deletion .gems
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
riak-client -v 1.4.0
riak-client -v 1.4.2
coveralls -v 0.6.7
protest -v 0.5.1
mocha -v 0.14.0
4 changes: 0 additions & 4 deletions .gems-test

This file was deleted.

7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ rvm:
- 1.9.3
- 2.0.0

services:
- riak

before_install:
- gem install dep
- ! 'echo root = \"/tmp/.riaktest\" > test/test_riak_server.toml'
- ! 'echo min_port = 15000 >> test/test_riak_server.toml'
- ! 'echo source = \"/usr/sbin\" >> test/test_riak_server.toml'
- ulimit -n 4096

install:
- dep install
- dep install -f .gems-test
20 changes: 2 additions & 18 deletions rakefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
task :default => :test

desc 'Start riak test server'
task :start do
desc 'Run tests'
task :test do
require File.expand_path("./test/helper", File.dirname(__FILE__))
puts '..:: Starting riak test server ::..'
test_server.start
sleep 1
end

desc 'Run tests'
task :test => [:start] do
Dir["test/**/*_test.rb"].each { |file| load file }
end

at_exit do
if $server
puts '..:: Stopping riak test server ::..'
sleep 1

$server.drop
$server.stop
end
end
11 changes: 6 additions & 5 deletions test/associations/collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ class Comment
reference :weird_post, :Post
end

teardown do
flush_db!
setup do
randomize_bucket_name Post
randomize_bucket_name Comment
end

should 'return an empty array when there are not referenced objects' do
test 'return an empty array when there are not referenced objects' do
post = Post.new

assert post.comments.empty?
Expand All @@ -34,7 +35,7 @@ class Comment
assert !post.respond_to?(:comments=)
end

should 'return the array of Comments referencing this Post' do
test 'return the array of Comments referencing this Post' do
post = Post.create name: 'New'
comment1 = Comment.create post: post, text: 'one'
comment2 = Comment.create post: post, text: 'two'
Expand All @@ -56,7 +57,7 @@ class Comment
assert post.weird_comments.include?(comment2)
end

should 'update referenced object' do
test 'update referenced object' do
post = Post.create name: 'New'
comment = Comment.create text: 'First One'

Expand Down
5 changes: 3 additions & 2 deletions test/associations/reference_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class Comment
reference :weird_post, :Post
end

teardown do
flush_db!
setup do
randomize_bucket_name Post
randomize_bucket_name Comment
end

should 'return nil when there is no reference object' do
Expand Down
5 changes: 3 additions & 2 deletions test/associations/referenced_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class Comment
reference :weird_post, :Post
end

teardown do
flush_db!
setup do
randomize_bucket_name Post
randomize_bucket_name Comment
end

should 'return nil when there is no reference object' do
Expand Down
39 changes: 7 additions & 32 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))

unless File.exist?(File.expand_path("../test_riak_server.toml", __FILE__))
puts "Specify the location of your Riak installation in test/test_riak_server.toml"
exit(1)
end

require 'coveralls'
Coveralls.wear!

Expand All @@ -17,36 +12,16 @@

require "rubygems"
require "protest"
require 'toml'
require 'riak/test_server'
require "ork"

Riak.disable_list_keys_warnings = true
Protest.report_with(:progress)

def test_server
$server ||= begin
path = File.expand_path("../test_riak_server.toml", __FILE__)
config = TOML.load_file(path, symbolize_keys: true)

server = Riak::TestServer.create(root: config[:root],
source: config[:source],
min_port: config[:min_port])


Ork.connect(:test, {
http_port: server.http_port,
pb_port: server.pb_port
})

server
rescue => e
puts "Can't run Ork tests without the test server."
puts e.inspect
exit(1)
end
end

def flush_db!
test_server.drop
def randomize_bucket_name(klass)
klass.bucket_name= [
'test',
klass.to_s,
Time.now.to_i,
rand(36**10).to_s(36)
].join('-')
end
5 changes: 1 addition & 4 deletions test/model/finders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ class Human

Protest.describe 'Finders' do
setup do
randomize_bucket_name Human
@human1 = Human.create(name: 'Tony', last_name: 'Montana')
end

teardown do
flush_db!
end

test 'raise an exception on load when a request fails' do
exception = Riak::HTTPFailedRequest.new(:get, 200, 401, {}, {})
Riak::RObject.any_instance.stubs(:reload).raises(exception)
Expand Down
6 changes: 3 additions & 3 deletions test/model/indices_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Dog
end

Protest.describe 'Indices' do
teardown do
flush_db!
setup do
randomize_bucket_name Dog
end

test 'have an indices list' do
Expand Down Expand Up @@ -40,7 +40,7 @@ class Dog
assert_equal Set['Athos'], robject.indexes['name_bin']
end

test 'prevent save when on an UniqueIndexViolation error' do
test 'prevent save on UniqueIndexViolation error' do
Dog.create(age: 14)
dog = Dog.new(name: 'Unsaved', age: 14)
begin
Expand Down
4 changes: 4 additions & 0 deletions test/model/model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Event

context 'Instance' do
setup do
randomize_bucket_name Event

@event = Event.new(name: 'Ruby')
end

Expand Down Expand Up @@ -129,6 +131,8 @@ class Event

context 'Equality' do
setup do
randomize_bucket_name Event

@event = Event.new(name: 'Ruby')
@other = Event.new(name: 'Emerald')
end
Expand Down
15 changes: 0 additions & 15 deletions test/test_riak_server.toml.example

This file was deleted.

0 comments on commit e8dd047

Please sign in to comment.