-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of #1
- Loading branch information
Showing
12 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.gem | ||
dump.rdb | ||
Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "rake/testtask" | ||
|
||
Rake::TestTask.new do |t| | ||
t.libs << "test" | ||
t.test_files = FileList['test/test*.rb'] | ||
t.verbose = true | ||
end | ||
|
||
task default: :test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require "securerandom" | ||
|
||
module Helpers | ||
REDIS_HOST = "127.0.0.1".freeze | ||
|
||
def rand_id | ||
SecureRandom.hex(4) | ||
end | ||
|
||
def exec_build(path, args="") | ||
worker_id = rand_id | ||
build_id = rand_id | ||
|
||
Dir.chdir(File.join("test", "sample_suites", path)) do | ||
out = `bundle exec rspecq --worker #{worker_id} --build #{build_id} #{args}` | ||
puts out if ENV["RSPECQ_DEBUG"] | ||
end | ||
|
||
assert_equal 0, $?.exitstatus | ||
|
||
queue = RSpecQ::Queue.new(build_id, worker_id, REDIS_HOST) | ||
assert_queue_well_formed(queue) | ||
|
||
return queue | ||
end | ||
|
||
def assert_queue_well_formed(queue, msg=nil) | ||
redis = queue.redis | ||
heartbeats = redis.zrange( | ||
queue.send(:key_worker_heartbeats), 0, -1, withscores: true) | ||
|
||
assert queue.published? | ||
assert queue.exhausted? | ||
assert_operator heartbeats.size, :>=, 0 | ||
assert heartbeats.all? { |hb| Time.at(hb.last) <= Time.now } | ||
end | ||
|
||
def assert_build_not_flakey(queue) | ||
assert_empty queue.requeued_jobs | ||
end | ||
|
||
def assert_processed_jobs(exp, queue) | ||
assert_equal exp.sort, queue.processed_jobs.sort | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Sample RSpec suites, used as fixtures in the tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
RSpec.describe do | ||
it "I should not be executed!" do | ||
expect(1).to eq 2 | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
test/sample_suites/different_spec_path/mytests/qwe_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
RSpec.describe do | ||
context "foo" do | ||
describe "abc" do | ||
it { expect(false).to be false } | ||
end | ||
end | ||
|
||
context "bar" do | ||
describe "dfg" do | ||
it { expect(true).to be true } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
RSpec.describe do | ||
it { expect(false).to be false } | ||
it { expect(1).to be 2 } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
RSpec.describe do | ||
it { expect(true).to be true } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
RSpec.describe do | ||
it do | ||
$tries ||= 0 | ||
$tries += 1 | ||
|
||
expect($tries).to eq 3 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
RSpec.describe do | ||
it { expect(true).to be true } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require "minitest/autorun" | ||
require "rspecq" | ||
require "helpers" | ||
|
||
class TestEndToEnd < Minitest::Test | ||
include Helpers | ||
|
||
def setup | ||
Redis.new(host: REDIS_HOST).flushdb | ||
end | ||
|
||
def test_suite_with_legit_failures | ||
queue = exec_build("failing_suite") | ||
|
||
refute queue.build_successful? | ||
|
||
assert_processed_jobs [ | ||
"./spec/foo_spec.rb", | ||
"./spec/bar_spec.rb", | ||
"./spec/bar_spec.rb[1:2]", | ||
], queue | ||
|
||
assert_equal 3+RSpecQ::MAX_REQUEUES, queue.example_count | ||
|
||
assert_equal({ "./spec/bar_spec.rb[1:2]" => "3" }, queue.requeued_jobs) | ||
end | ||
|
||
def test_passing_suite | ||
queue = exec_build("passing_suite") | ||
|
||
assert queue.build_successful? | ||
assert_build_not_flakey(queue) | ||
assert_equal 1, queue.example_count | ||
assert_equal ["./spec/foo_spec.rb"], queue.processed_jobs | ||
end | ||
|
||
def test_flakey_suite | ||
queue = exec_build("flakey_suite") | ||
|
||
assert queue.build_successful? | ||
assert_processed_jobs [ | ||
"./spec/foo_spec.rb", | ||
"./spec/foo_spec.rb[1:1]", | ||
], queue | ||
|
||
assert_equal({ "./spec/foo_spec.rb[1:1]" => "2" }, queue.requeued_jobs) | ||
end | ||
|
||
def test_scheduling_by_file_and_custom_spec_path | ||
queue = exec_build("different_spec_path", "mytests/qwe_spec.rb") | ||
|
||
assert queue.build_successful? | ||
assert_build_not_flakey(queue) | ||
assert_equal 2, queue.example_count | ||
assert_processed_jobs ["./mytests/qwe_spec.rb"], queue | ||
end | ||
end |