diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..dd44d561 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,86 @@ +# Inspired from: +# - https://github.com/cockroachdb/sqlalchemy-cockroachdb/blob/master/.github/workflows/ci.yml +# - https://github.com/rgeo/activerecord-postgis-adapter/blob/master/.github/workflows/tests.yml +name: Test + +on: + # Triggers the workflow on push or pull request events. + push: + # This should disable running the workflow on tags, according to the + # on.. GitHub Actions docs. + branches: + - "*" + pull_request: + types: [opened, reopened, synchronize] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# This allows a subsequently queued workflow run to interrupt previous runs. +concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + crdb: [v23.1.5] + ruby: [ruby-head] + name: Test (crdb=${{ matrix.crdb }}, ruby=${{ matrix.ruby }}) + steps: + - name: Set Up Actions + uses: actions/checkout@v3 + - name: Install GEOS + run: sudo apt-get install libgeos-dev + - name: Set Up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Install and Start Cockroachdb + run: | + # Download CockroachDB + wget -qO- https://binaries.cockroachdb.com/cockroach-${{ matrix.crdb }}.linux-amd64.tgz | tar xvz + + export PATH=./cockroach-${{ matrix.crdb }}.linux-amd64/:$PATH + readonly urlfile=cockroach-url + + # Start a CockroachDB server and wait for it to become ready. + rm -f "$urlfile" + rm -rf cockroach-data + # Start CockroachDB. + cockroach start-single-node --max-sql-memory=25% --cache=25% --insecure --host=localhost --spatial-libs=./cockroach-${{ matrix.crdb }}.linux-amd64/lib --listening-url-file="$urlfile" >/dev/null 2>&1 & + # Ensure CockroachDB is stopped on script exit. + # Wait until CockroachDB has started. + for i in {0..3}; do + [[ -f "$urlfile" ]] && break + backoff=$((2 ** i)) + echo "server not yet available; sleeping for $backoff seconds" + sleep $backoff + done + cockroach sql --insecure -e " + CREATE DATABASE activerecord_unittest; + CREATE DATABASE activerecord_unittest2; + SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false; + SET CLUSTER SETTING sql.stats.histogram_collection.enabled = false; + SET CLUSTER SETTING jobs.retention_time = '180s'; + SET CLUSTER SETTING sql.defaults.experimental_alter_column_type.enabled = 'true'; + + ALTER RANGE default CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30; + ALTER TABLE system.public.jobs CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30; + ALTER RANGE meta CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30; + ALTER RANGE system CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30; + ALTER RANGE liveness CONFIGURE ZONE USING num_replicas = 1, gc.ttlseconds = 30; + + SET CLUSTER SETTING kv.range_merge.queue_interval = '50ms'; + SET CLUSTER SETTING kv.raft_log.disable_synchronization_unsafe = 'true'; + SET CLUSTER SETTING jobs.registry.interval.cancel = '180s'; + SET CLUSTER SETTING jobs.registry.interval.gc = '30s'; + SET CLUSTER SETTING kv.range_split.by_load_merge_delay = '5s'; + + SET CLUSTER SETTING sql.defaults.experimental_temporary_tables.enabled = 'true'; + " + - name: Test + run: bundle exec rake test diff --git a/Gemfile b/Gemfile index 04720b61..8c4d1671 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ module RailsTag def gemspec_requirement File - .foreach("activerecord-cockroachdb-adapter.gemspec", chomp: true) + .foreach(File.expand_path("activerecord-cockroachdb-adapter.gemspec", __dir__), chomp: true) .find { _1[/add_dependency\s.activerecord.,\s.(.*)./] } Gem::Requirement.new(Regexp.last_match(1)) diff --git a/test/cases/adapters/postgresql/active_schema_test.rb b/test/cases/adapters/postgresql/active_schema_test.rb index ea01ba15..682f3624 100644 --- a/test/cases/adapters/postgresql/active_schema_test.rb +++ b/test/cases/adapters/postgresql/active_schema_test.rb @@ -64,8 +64,8 @@ def test_add_index end private - def method_missing(method_symbol, *arguments) - ActiveRecord::Base.connection.send(method_symbol, *arguments) + def method_missing(...) + ActiveRecord::Base.connection.send(...) end end end diff --git a/test/cases/connection_adapters/schema_cache_test.rb b/test/cases/connection_adapters/schema_cache_test.rb index 73b71b60..663a3d5a 100644 --- a/test/cases/connection_adapters/schema_cache_test.rb +++ b/test/cases/connection_adapters/schema_cache_test.rb @@ -15,7 +15,7 @@ def setup # See test/excludes/ActiveRecord/ConnectionAdapters/SchemaCacheTest.rb def test_yaml_loads_5_1_dump body = File.open(schema_dump_path).read - cache = YAML.load(body) + cache = YAML.unsafe_load(body) assert_no_queries do assert_equal 11, cache.columns("posts").size @@ -32,7 +32,7 @@ def test_yaml_loads_5_1_dump # See test/excludes/ActiveRecord/ConnectionAdapters/SchemaCacheTest.rb def test_yaml_loads_5_1_dump_without_indexes_still_queries_for_indexes body = File.open(schema_dump_path).read - @cache = YAML.load(body) + @cache = YAML.unsafe_load(body) # Simulate assignment in railtie after loading the cache. old_cache, @connection.schema_cache = @connection.schema_cache, @cache @@ -51,7 +51,7 @@ def test_yaml_loads_5_1_dump_without_indexes_still_queries_for_indexes # See test/excludes/ActiveRecord/ConnectionAdapters/SchemaCacheTest.rb def test_yaml_loads_5_1_dump_without_database_version_still_queries_for_database_version body = File.open(schema_dump_path).read - @cache = YAML.load(body) + @cache = YAML.unsafe_load(body) # Simulate assignment in railtie after loading the cache. old_cache, @connection.schema_cache = @connection.schema_cache, @cache diff --git a/test/support/rake_helpers.rb b/test/support/rake_helpers.rb index d34efd09..07a82807 100644 --- a/test/support/rake_helpers.rb +++ b/test/support/rake_helpers.rb @@ -12,13 +12,12 @@ def test_files ar_test_files = ENV.fetch('TEST_FILES_AR', '') cr_test_files = ENV.fetch('TEST_FILES', '') - return all_test_file if ar_test_files.empty? && cr_test_files.empty? + return all_test_files if ar_test_files.empty? && cr_test_files.empty? ar_test_files = ar_test_files. split(','). map { |file| File.join ARTest::CockroachDB.root_activerecord, file.strip }. - then { _1.prepend(COCKROACHDB_TEST_HELPER) unless _1.empty? }. - prepend(COCKROACHDB_TEST_HELPER) + tap { _1.prepend(COCKROACHDB_TEST_HELPER) unless _1.empty? } cr_test_files = cr_test_files.split(',').map(&:strip) @@ -28,7 +27,7 @@ def test_files def all_test_files activerecord_test_files = Dir. glob("#{ARTest::CockroachDB.root_activerecord}/test/cases/**/*_test.rb"). - reject { _1.match?(%r(/adapters/(?:mysql2|sqlite3)/) }. + reject { _1.match?(%r(/adapters/(?:mysql2|sqlite3)/)) }. prepend(COCKROACHDB_TEST_HELPER) cockroachdb_test_files = Dir.glob('test/cases/**/*_test.rb')