-
Notifications
You must be signed in to change notification settings - Fork 23
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
11 changed files
with
117 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,4 @@ | ||
*.gem | ||
dump.rdb | ||
Gemfile.lock | ||
spec/examples.txt |
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,2 @@ | ||
--require spec_helper | ||
--format progress |
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,35 @@ | ||
require "securerandom" | ||
|
||
module Helpers | ||
REDIS_HOST = "127.0.0.1".freeze | ||
|
||
def rand_id | ||
SecureRandom.hex(4) | ||
end | ||
|
||
def exec_build(path) | ||
worker_id = rand_id | ||
build_id = rand_id | ||
|
||
Dir.chdir(File.join("test", "sample_suites", path)) do | ||
`bundle exec rspecq --worker #{worker_id} --build #{build_id}` | ||
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 | ||
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,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,48 @@ | ||
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_equal [ | ||
"./spec/foo_spec.rb", | ||
"./spec/bar_spec.rb", | ||
"./spec/bar_spec.rb[1:2]", | ||
].sort, queue.processed_jobs.sort | ||
|
||
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_equal 1, queue.example_count | ||
assert_empty queue.requeued_jobs | ||
assert_equal ["./spec/foo_spec.rb"], queue.processed_jobs | ||
end | ||
|
||
def test_flakey_suite | ||
queue = exec_build("flakey_suite") | ||
|
||
assert queue.build_successful? | ||
assert_equal [ | ||
"./spec/foo_spec.rb", | ||
"./spec/foo_spec.rb[1:1]", | ||
].sort, queue.processed_jobs.sort | ||
|
||
assert_equal({ "./spec/foo_spec.rb[1:1]" => "2" }, queue.requeued_jobs) | ||
end | ||
end |