Skip to content

Commit

Permalink
test: replace sleep with healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Aug 2, 2024
1 parent 2765a6d commit 8266205
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 27 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ jobs:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- run: gem update bundler
- run: make install
- run: make download_all_libs
- run: make download_libs
- run: make test
# - run: make publish_pacts
# env:
Expand All @@ -55,20 +55,20 @@ jobs:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
if: matrix.arch == 'arm64'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
if: matrix.arch == 'arm64'
- run: make download_all_libs
- run: make download_libs
- run: |
docker run --platform=linux/${{ matrix.arch }} \
--rm -v $PWD:/app ruby:${{ matrix.ruby-version }}-alpine \
/bin/sh -c \
'apk add --no-cache make gcc musl-dev libffi libffi-dev git bash curl && \
cd /app && make download_all_libs && make install && make test'
cd /app && make download_all_libs && git config --global --add safe.directory /app && make install && make test'
# - run: |
# docker run --platform=linux/${{ matrix.arch }} \
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with: # gRPC demo requires Ruby < 3.0
ruby-version: ${{ matrix.ruby-version }}
Expand All @@ -115,7 +115,7 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: gem update bundler
- run: make install
- run: make download_all_libs
- run: make download_libs
- run: make grpc


Expand All @@ -138,7 +138,7 @@ jobs:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
Expand Down
15 changes: 14 additions & 1 deletion compatibility-suite/step_definitions/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,20 @@

@pid = Process.spawn("ruby compatibility-suite/support/test_servers/#{filename}-server.rb")
puts @pid
sleep(2)
# Check server is up
uri = URI.parse('http://localhost:8080/__messages')
response = nil
10.times do
response = Net::HTTP.get_response(uri)
break if response.code == '200'
rescue Errno::ECONNREFUSED
sleep(1)
end
if response && response.code == '200'
puts 'Healthcheck passed'
else
puts 'Healthcheck failed'
end
end

After do
Expand Down
28 changes: 19 additions & 9 deletions compatibility-suite/support/test_servers/basic-server.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@

require 'webrick'
require 'json'
def start_server
server = WEBrick::HTTPServer.new(Port: 8080)
require 'optparse'

options = {}
OptionParser.new do |opts|
opts.banner = 'Usage: server.rb [options]'

server.mount_proc('/__messages') do |_req, res|
puts _req
res['content-type'] = 'application/json'
res.body = '{"one":"cat","two":"b"}'
opts.on('-p', '--port PORT', Integer, 'Port number to listen on (default: 8000)') do |port|
options[:port] = port
end
end.parse!

port = options[:port] || 8080

server.start
server = WEBrick::HTTPServer.new(Port: port)

server.mount_proc('/__messages') do |_req, res|
puts _req
res['content-type'] = 'application/json'
res.body = '{"one":"cat","two":"b"}'
end

start_server
trap('INT') { server.shutdown }

server.start
26 changes: 18 additions & 8 deletions compatibility-suite/support/test_servers/basic2-server.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
require 'webrick'
require 'json'
def start_server
server = WEBrick::HTTPServer.new(Port: 8080)
require 'optparse'

server.mount_proc('/__messages') do |_req, res|
puts _req
res['content-type'] = 'application/json'
res.body = '{"one":"cat","two":"b"}'
options = {}
OptionParser.new do |opts|
opts.banner = 'Usage: server.rb [options]'

opts.on('-p', '--port PORT', Integer, 'Port number to listen on (default: 8000)') do |port|
options[:port] = port
end
end.parse!

port = options[:port] || 8080
server = WEBrick::HTTPServer.new(Port: port)

server.start
server.mount_proc('/__messages') do |_req, res|
puts _req
res['content-type'] = 'application/json'
res.body = '{"one":"cat","two":"b"}'
end

start_server
trap('INT') { server.shutdown }

server.start
16 changes: 15 additions & 1 deletion spec/pactffi_verifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@
before(:all) do
# running in process, results in requests only hitting server when verification complete
@pid = Process.spawn('ruby provider.rb')
sleep(2)
puts @pid
# Check server is up
uri = URI.parse('http://localhost:8000/api/books')
response = nil
10.times do
response = Net::HTTP.get_response(uri)
break if response.code == '404'
rescue Errno::ECONNREFUSED
sleep(1)
end
if response && response.code == '404'
puts 'Healthcheck passed'
else
puts 'Healthcheck failed'
end
end
after(:all) do
puts @pid
Expand Down

0 comments on commit 8266205

Please sign in to comment.