Skip to content

Commit

Permalink
Test suite run with concurrent workers
Browse files Browse the repository at this point in the history
Part of #1
  • Loading branch information
agis committed Jul 22, 2020
1 parent 42908d0 commit ea15717
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 7 deletions.
15 changes: 9 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ rvm:
- 2.7
- ruby-head
env:
- RSPEC_CORE=3.8.0
- RSPEC_CORE=3.8.1
- RSPEC_CORE=3.8.2
- RSPEC_CORE=3.9.0
- RSPEC_CORE=3.9.1
- RSPEC_CORE=3.9.2
global:
#- RSPECQ_DEBUG=
jobs:
- RSPEC_CORE=3.8.0
- RSPEC_CORE=3.8.1
- RSPEC_CORE=3.8.2
- RSPEC_CORE=3.9.0
- RSPEC_CORE=3.9.1
- RSPEC_CORE=3.9.2

jobs:
allow_failures:
Expand Down
5 changes: 5 additions & 0 deletions test/sample_suites/passing_concurrent/spec/a_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "shared"

RSpec.describe do
it_behaves_like "kinda slow example"
end
5 changes: 5 additions & 0 deletions test/sample_suites/passing_concurrent/spec/b_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "shared"

RSpec.describe do
it_behaves_like "kinda slow example"
end
5 changes: 5 additions & 0 deletions test/sample_suites/passing_concurrent/spec/c_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "shared"

RSpec.describe do
it_behaves_like "kinda slow example"
end
5 changes: 5 additions & 0 deletions test/sample_suites/passing_concurrent/spec/d_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "shared"

RSpec.describe do
it_behaves_like "kinda slow example"
end
5 changes: 5 additions & 0 deletions test/sample_suites/passing_concurrent/spec/e_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "shared"

RSpec.describe do
it_behaves_like "kinda slow example"
end
6 changes: 6 additions & 0 deletions test/sample_suites/passing_concurrent/spec/shared.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RSpec.shared_examples "kinda slow example" do
it do
sleep 2
expect(true).to be true
end
end
44 changes: 44 additions & 0 deletions test/test_concurrent_workers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require "test_helpers"

class TestConcurrentWorkers < RSpecQTest
# The 'passing_concurrent' suite contains 5 spec files each containing a
# single example taking 2". We spawn that many workers so we expect roughly
# 2 second total execution time. We some more to account for fork and
# rspec boot and other setup overheads
def test_passing_suite
build_id = rand_id
pids = []
job_count = 5

start = Process.clock_gettime(Process::CLOCK_MONOTONIC)

job_count.times do
pids << start_worker(build_id: build_id, suite: "passing_concurrent")
end

pids.each { |p| Process.wait(p) }

elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start

assert_operator elapsed, :<, 5

queue = RSpecQ::Queue.new(build_id, "foo", REDIS_HOST)

assert_queue_well_formed(queue)
assert queue.build_successful?
assert_equal job_count, queue.example_count
assert_equal job_count, queue.redis.zcard(queue.key_worker_heartbeats)
end

def test_flakey_suite
skip
end

def test_failing_suite_with_requeues
skip
end

def test_passing_suite_with_faulty_worker
skip
end
end
11 changes: 10 additions & 1 deletion test/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module TestHelpers
REDIS_HOST = "127.0.0.1".freeze
EXEC_CMD = "bundle exec rspecq"

def rand_id
SecureRandom.hex(4)
Expand All @@ -23,7 +24,7 @@ def exec_build(path, args="")
build_id = rand_id

Dir.chdir(suite_path(path)) do
out = `bundle exec rspecq --worker #{worker_id} --build #{build_id} #{args}`
out = `#{EXEC_CMD} --worker #{worker_id} --build #{build_id} #{args}`
puts out if ENV["RSPECQ_DEBUG"]
end

Expand Down Expand Up @@ -57,6 +58,14 @@ def assert_processed_jobs(exp, queue)
def suite_path(path)
File.join("test", "sample_suites", path)
end

def start_worker(build_id:, worker_id: rand_id, suite:)
Process.spawn(
"#{EXEC_CMD} -w #{worker_id} -b #{build_id}",
chdir: suite_path(suite),
out: (ENV["RSPECQ_DEBUG"] ? :out : "/dev/null"),
)
end
end

# To be subclassed from all test cases.
Expand Down

0 comments on commit ea15717

Please sign in to comment.