diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0c1c2b0..c7306d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -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 }} \ @@ -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 }} @@ -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 @@ -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 }} diff --git a/compatibility-suite/step_definitions/steps.rb b/compatibility-suite/step_definitions/steps.rb index 7cd239e..df87d41 100644 --- a/compatibility-suite/step_definitions/steps.rb +++ b/compatibility-suite/step_definitions/steps.rb @@ -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 diff --git a/compatibility-suite/support/test_servers/basic-server.rb b/compatibility-suite/support/test_servers/basic-server.rb index fe9e7ed..dfe287b 100644 --- a/compatibility-suite/support/test_servers/basic-server.rb +++ b/compatibility-suite/support/test_servers/basic-server.rb @@ -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 diff --git a/compatibility-suite/support/test_servers/basic2-server.rb b/compatibility-suite/support/test_servers/basic2-server.rb index b40b955..1446348 100644 --- a/compatibility-suite/support/test_servers/basic2-server.rb +++ b/compatibility-suite/support/test_servers/basic2-server.rb @@ -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 diff --git a/spec/pactffi_verifier_spec.rb b/spec/pactffi_verifier_spec.rb index f572f55..0b3ae7c 100644 --- a/spec/pactffi_verifier_spec.rb +++ b/spec/pactffi_verifier_spec.rb @@ -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