From 145577a96a8bf2ec3b7aea1dac2afdb1013cae69 Mon Sep 17 00:00:00 2001 From: Ankitha Damodara Date: Fri, 14 Jun 2024 08:50:02 +0100 Subject: [PATCH 1/7] add github workflows --- .circleci/config.yml | 59 ------------------------------------- .github/workflows/specs.yml | 48 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 59 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/specs.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index ba26bc4..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,59 +0,0 @@ -version: 2.1 - -references: - bundle_install: &bundle_install - run: - name: Bundle - command: | - gem install bundler --no-document && \ - bundle config set no-cache 'true' && \ - bundle config set jobs '4' && \ - bundle config set retry '3' && \ - bundle install - - cache_bundle: &cache_bundle - save_cache: - key: bundle-<< parameters.ruby_version >>-{{ checksum "que.gemspec" }}-{{ checksum "Gemfile" }} - paths: - - vendor/bundle - - restore_bundle: &restore_bundle - restore_cache: - key: bundle-<< parameters.ruby_version >>-{{ checksum "que.gemspec" }}-{{ checksum "Gemfile" }} - -jobs: - rspec: - working_directory: ~/que - parameters: - ruby_version: - type: string - docker: - - image: cimg/ruby:<< parameters.ruby_version >> - environment: - PGDATABASE: que-test - PGUSER: ubuntu - PGPASSWORD: password - PGHOST: localhost - - image: postgres:11.2 - environment: - POSTGRES_DB: que-test - POSTGRES_USER: ubuntu - POSTGRES_PASSWORD: password - steps: - - add_ssh_keys - - checkout - - *restore_bundle - - *bundle_install - - *cache_bundle - - run: - name: Run specs - command: bundle exec rspec - -workflows: - version: 2 - tests: - jobs: - - rspec: - matrix: - parameters: - ruby_version: ["2.6", "2.7", "3.0"] diff --git a/.github/workflows/specs.yml b/.github/workflows/specs.yml new file mode 100644 index 0000000..d07b857 --- /dev/null +++ b/.github/workflows/specs.yml @@ -0,0 +1,48 @@ +name: Run Specs + +on: + push: +permissions: + contents: read + # We need write access to the id-token to use workload identity federation + id-token: write + packages: read + # Needed for getting PR labels + pull-requests: read + + +env: + PGDATABASE: que-test + PGUSER: ubuntu + PGPASSWORD: password + PGHOST: localhost + +jobs: + rspec: + runs-on: ubuntu-latest + strategy: + matrix: + ruby_version: ["2.6", "2.7", "3.0"] + + services: + postgres: + image: postgres:11.2 + env: + POSTGRES_DB: que-test + POSTGRES_USER: ubuntu + POSTGRES_PASSWORD: password + POSTGRES_HOST_AUTH_METHOD: trust + ports: + - 5432:5432 + + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: "${{ matrix.ruby-version }}" + + - name: Run Specs + run: | + bundle exec rspec \ No newline at end of file From d520105ba87bb66737649bc1a4b2bfde12e17e38 Mon Sep 17 00:00:00 2001 From: Ankitha Damodara Date: Fri, 14 Jun 2024 09:35:16 +0100 Subject: [PATCH 2/7] update secret variable --- .github/workflows/{specs.yml => tests.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{specs.yml => tests.yml} (100%) diff --git a/.github/workflows/specs.yml b/.github/workflows/tests.yml similarity index 100% rename from .github/workflows/specs.yml rename to .github/workflows/tests.yml From fa362d4282592d55e0372399b6f627f8ad27a70c Mon Sep 17 00:00:00 2001 From: Ankitha Damodara Date: Fri, 14 Jun 2024 11:27:03 +0100 Subject: [PATCH 3/7] update config --- .github/workflows/tests.yml | 42 +++++++++++++++++-------------------- Gemfile | 2 +- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d07b857..ce199d8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,40 +1,37 @@ -name: Run Specs +name: tests on: push: -permissions: - contents: read - # We need write access to the id-token to use workload identity federation - id-token: write - packages: read - # Needed for getting PR labels - pull-requests: read - - -env: - PGDATABASE: que-test - PGUSER: ubuntu - PGPASSWORD: password - PGHOST: localhost jobs: rspec: - runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - ruby_version: ["2.6", "2.7", "3.0"] - + ruby_version: ["3.0", "3.1", "3.2", "3.3"] + + runs-on: ubuntu-latest services: postgres: - image: postgres:11.2 + image: postgres:14.2 env: POSTGRES_DB: que-test POSTGRES_USER: ubuntu POSTGRES_PASSWORD: password - POSTGRES_HOST_AUTH_METHOD: trust ports: - 5432:5432 - + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 10 + + env: + PGDATABASE: que-test + PGUSER: ubuntu + PGPASSWORD: password + PGHOST: localhost + steps: - uses: actions/checkout@v3 - name: Set up Ruby @@ -42,7 +39,6 @@ jobs: with: bundler-cache: true ruby-version: "${{ matrix.ruby-version }}" - - - name: Run Specs + - name: Run specs run: | bundle exec rspec \ No newline at end of file diff --git a/Gemfile b/Gemfile index 883fa4d..7d1049b 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,6 @@ group :test do end gem 'prometheus-client', '~> 1.0' -gem 'prometheus_gcstat', git: 'git@github.com:gocardless/prometheus_gcstat_ruby' +# gem 'prometheus_gcstat', git: 'git@github.com:gocardless/prometheus_gcstat_ruby' gemspec From c5c9714b04299991502c753248299bda81f80a94 Mon Sep 17 00:00:00 2001 From: Ankitha Damodara Date: Wed, 3 Jul 2024 09:49:28 +0100 Subject: [PATCH 4/7] fix flaky tests --- spec/lib/que/locker_spec.rb | 7 +++++-- spec/lib/que/middleware/queue_collector_spec.rb | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/spec/lib/que/locker_spec.rb b/spec/lib/que/locker_spec.rb index 08cc4a7..505925d 100644 --- a/spec/lib/que/locker_spec.rb +++ b/spec/lib/que/locker_spec.rb @@ -94,8 +94,11 @@ def expect_to_lock_with(cursor:) context "with non-zero cursor expiry" do let(:cursor_expiry) { 5 } - before { allow(locker).to receive(:monotonic_now) { @epoch } } - + before do + # we need this to avoid flakiness during resetting the cursor + locker.instance_variable_get(:@queue_expires_at)[queue] = Process.clock_gettime(Process::CLOCK_MONOTONIC) + cursor_expiry + allow(locker).to receive(:monotonic_now) { @epoch } + end # This test simulates the repeated locking of jobs. We're trying to prove that # the locker will use the previous jobs ID as a cursor until the expiry has # elapsed, after which we'll reset. diff --git a/spec/lib/que/middleware/queue_collector_spec.rb b/spec/lib/que/middleware/queue_collector_spec.rb index 6d804f3..aa51021 100644 --- a/spec/lib/que/middleware/queue_collector_spec.rb +++ b/spec/lib/que/middleware/queue_collector_spec.rb @@ -4,7 +4,7 @@ RSpec.describe Que::Middleware::QueueCollector do subject(:collector) { described_class.new(->(_env) { nil }, options) } - let(:options) { {} } + let(:options) { {refresh_interval: 1.second} } let(:now) { postgres_now } let(:due_now_delay) { 1000.0 } let(:due_later_than_now_delay) { due_now_delay / 2 } From 4c74ed5098a18aeebccd553865c0608b80079361 Mon Sep 17 00:00:00 2001 From: Ankitha Damodara Date: Wed, 3 Jul 2024 09:51:17 +0100 Subject: [PATCH 5/7] remove github branch reference for prometheus gem --- .github/workflows/tests.yml | 2 +- Gemfile | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ce199d8..9945b21 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,7 +31,7 @@ jobs: PGUSER: ubuntu PGPASSWORD: password PGHOST: localhost - + BUNDLE_RUBYGEMS__PKG__GITHUB__COM: gocardless-robot-readonly:${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v3 - name: Set up Ruby diff --git a/Gemfile b/Gemfile index 7d1049b..1181f91 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,7 @@ group :test do end gem 'prometheus-client', '~> 1.0' -# gem 'prometheus_gcstat', git: 'git@github.com:gocardless/prometheus_gcstat_ruby' - +source "https://rubygems.pkg.github.com/gocardless" do + gem "prometheus_gcstat", "0.1.1" +end gemspec From 45642c13fdaba6f796bae0a18735f58407f9c4e4 Mon Sep 17 00:00:00 2001 From: Ankitha Damodara Date: Wed, 3 Jul 2024 15:45:09 +0100 Subject: [PATCH 6/7] add additional comments --- spec/lib/que/locker_spec.rb | 5 ++++- spec/lib/que/middleware/queue_collector_spec.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/lib/que/locker_spec.rb b/spec/lib/que/locker_spec.rb index 505925d..47f0db2 100644 --- a/spec/lib/que/locker_spec.rb +++ b/spec/lib/que/locker_spec.rb @@ -95,7 +95,10 @@ def expect_to_lock_with(cursor:) let(:cursor_expiry) { 5 } before do - # we need this to avoid flakiness during resetting the cursor + # we need this to avoid flakiness during resetting the cursor. + # Cursors are reset in the beginning when the locker class object is created. + # It is reset in handle_expired_cursors! method. Sometimes the execution is fast enough that + # the condition to reset is not met because the Process.clock_gettime remains same(monotonic_now method). locker.instance_variable_get(:@queue_expires_at)[queue] = Process.clock_gettime(Process::CLOCK_MONOTONIC) + cursor_expiry allow(locker).to receive(:monotonic_now) { @epoch } end diff --git a/spec/lib/que/middleware/queue_collector_spec.rb b/spec/lib/que/middleware/queue_collector_spec.rb index aa51021..ac42c90 100644 --- a/spec/lib/que/middleware/queue_collector_spec.rb +++ b/spec/lib/que/middleware/queue_collector_spec.rb @@ -4,7 +4,7 @@ RSpec.describe Que::Middleware::QueueCollector do subject(:collector) { described_class.new(->(_env) { nil }, options) } - let(:options) { {refresh_interval: 1.second} } + let(:options) { {refresh_interval: 0.1.second} } let(:now) { postgres_now } let(:due_now_delay) { 1000.0 } let(:due_later_than_now_delay) { due_now_delay / 2 } From c79a2f75fceaec3fc64a874646be3f34ccc51d79 Mon Sep 17 00:00:00 2001 From: Ankitha Damodara Date: Wed, 3 Jul 2024 15:55:08 +0100 Subject: [PATCH 7/7] add support of 2.x ruby version in specs --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 1181f91..cba9598 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,6 @@ end gem 'prometheus-client', '~> 1.0' source "https://rubygems.pkg.github.com/gocardless" do - gem "prometheus_gcstat", "0.1.1" + gem "prometheus_gcstat" end gemspec