From 0d323c74bf6467d073574e30354c6f2762dad72a Mon Sep 17 00:00:00 2001 From: eMancu Date: Sat, 5 Oct 2013 09:25:11 -0300 Subject: [PATCH 1/5] Update .gems file --- .gems | 6 +++++- .gems-test | 4 ---- 2 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 .gems-test diff --git a/.gems b/.gems index 0449201..81ba429 100644 --- a/.gems +++ b/.gems @@ -1 +1,5 @@ -riak-client -v 1.4.0 +riak-client -v 1.4.2 +coveralls -v 0.6.7 +toml-rb -v 0.1.3 +protest -v 0.5.1 +mocha -v 0.14.0 diff --git a/.gems-test b/.gems-test deleted file mode 100644 index 026c47d..0000000 --- a/.gems-test +++ /dev/null @@ -1,4 +0,0 @@ -coveralls -v 0.6.7 -toml-rb -v 0.1.3 -protest -v 0.5.1 -mocha -v 0.14.0 From 70041796af6d1607a625130b1653fe13db1e8ed8 Mon Sep 17 00:00:00 2001 From: eMancu Date: Sat, 5 Oct 2013 11:21:55 -0300 Subject: [PATCH 2/5] Optimize tests and fix casual failure tests Randomize bucket names is faster than start and stop Test Server or delete all keys. --- test/associations/collection_test.rb | 11 ++++++----- test/associations/reference_test.rb | 5 +++-- test/associations/referenced_test.rb | 5 +++-- test/helper.rb | 9 +++++++-- test/model/finders_test.rb | 5 +---- test/model/indices_test.rb | 6 +++--- test/model/model_test.rb | 4 ++++ 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/test/associations/collection_test.rb b/test/associations/collection_test.rb index b06cfa5..b2d2c4d 100644 --- a/test/associations/collection_test.rb +++ b/test/associations/collection_test.rb @@ -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? @@ -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' @@ -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' diff --git a/test/associations/reference_test.rb b/test/associations/reference_test.rb index cf77641..ea4ca29 100644 --- a/test/associations/reference_test.rb +++ b/test/associations/reference_test.rb @@ -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 diff --git a/test/associations/referenced_test.rb b/test/associations/referenced_test.rb index d4059b1..19715d8 100644 --- a/test/associations/referenced_test.rb +++ b/test/associations/referenced_test.rb @@ -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 diff --git a/test/helper.rb b/test/helper.rb index 0893d24..20860cb 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -47,6 +47,11 @@ def test_server 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 diff --git a/test/model/finders_test.rb b/test/model/finders_test.rb index eee648d..5e31fdf 100644 --- a/test/model/finders_test.rb +++ b/test/model/finders_test.rb @@ -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) diff --git a/test/model/indices_test.rb b/test/model/indices_test.rb index 50e20ce..32ea658 100644 --- a/test/model/indices_test.rb +++ b/test/model/indices_test.rb @@ -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 @@ -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 diff --git a/test/model/model_test.rb b/test/model/model_test.rb index c6c85ae..1f593d6 100644 --- a/test/model/model_test.rb +++ b/test/model/model_test.rb @@ -42,6 +42,8 @@ class Event context 'Instance' do setup do + randomize_bucket_name Event + @event = Event.new(name: 'Ruby') end @@ -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 From f7aa63b4d5646aad2a08e849126d7883d1b4d9b1 Mon Sep 17 00:00:00 2001 From: eMancu Date: Sat, 5 Oct 2013 11:22:51 -0300 Subject: [PATCH 3/5] Remove TestServer since the new Riak broke it. Also it was so slow that is better to start risk and run tests. --- rakefile | 20 ++------------------ test/helper.rb | 30 ------------------------------ test/test_riak_server.toml.example | 15 --------------- 3 files changed, 2 insertions(+), 63 deletions(-) delete mode 100644 test/test_riak_server.toml.example diff --git a/rakefile b/rakefile index b23f5df..4662c04 100644 --- a/rakefile +++ b/rakefile @@ -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 diff --git a/test/helper.rb b/test/helper.rb index 20860cb..3ced5a6 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -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! @@ -17,36 +12,11 @@ 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 randomize_bucket_name(klass) klass.bucket_name= [ 'test', diff --git a/test/test_riak_server.toml.example b/test/test_riak_server.toml.example deleted file mode 100644 index 410abd7..0000000 --- a/test/test_riak_server.toml.example +++ /dev/null @@ -1,15 +0,0 @@ -# This is where the test server node will be generated. Something on -# /tmp is usually ok. -root = "/tmp/.ork_node" -min_port = 15000 - -# This is where Riak is installed on your system, that is, the path to -# the 'riak' and 'riak-admin' scripts. I use a self-built node, but -# here's where it will generally be on various platforms: -# -# Linux: /usr/sbin -# Solaris/OpenSolaris: /opt/riak/bin -# Mac OS/X (Homebrew): /usr/local/bin -# Source/Self built: /path/to/your/install/rel/riak/bin -# -source = "/usr/local/bin" From e47a1bea275c43996d33aa40804fe536e5e188f4 Mon Sep 17 00:00:00 2001 From: eMancu Date: Sat, 5 Oct 2013 11:24:36 -0300 Subject: [PATCH 4/5] Remove toml-rb gem --- .gems | 1 - 1 file changed, 1 deletion(-) diff --git a/.gems b/.gems index 81ba429..97f7b0d 100644 --- a/.gems +++ b/.gems @@ -1,5 +1,4 @@ riak-client -v 1.4.2 coveralls -v 0.6.7 -toml-rb -v 0.1.3 protest -v 0.5.1 mocha -v 0.14.0 From 747a9a2c44d220b08512c553a6d60b9e64e5bdc1 Mon Sep 17 00:00:00 2001 From: eMancu Date: Sat, 5 Oct 2013 11:26:36 -0300 Subject: [PATCH 5/5] Update travis configuration --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c15cfba..8ec516d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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