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/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..9945b21 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,44 @@ +name: tests + +on: + push: + +jobs: + rspec: + strategy: + fail-fast: false + matrix: + ruby_version: ["3.0", "3.1", "3.2", "3.3"] + + runs-on: ubuntu-latest + services: + postgres: + image: postgres:14.2 + env: + POSTGRES_DB: que-test + POSTGRES_USER: ubuntu + POSTGRES_PASSWORD: password + 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 + BUNDLE_RUBYGEMS__PKG__GITHUB__COM: gocardless-robot-readonly:${{ secrets.GITHUB_TOKEN }} + 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 diff --git a/Gemfile b/Gemfile index 883fa4d..cba9598 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" +end gemspec diff --git a/spec/lib/que/locker_spec.rb b/spec/lib/que/locker_spec.rb index 08cc4a7..47f0db2 100644 --- a/spec/lib/que/locker_spec.rb +++ b/spec/lib/que/locker_spec.rb @@ -94,8 +94,14 @@ 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. + # 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 # 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..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) { {} } + 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 }