From 324116968e907199870413fdbe20c83531e36774 Mon Sep 17 00:00:00 2001 From: Ulysse Buonomo Date: Sun, 23 Jul 2023 08:41:30 -0500 Subject: [PATCH] chore(ci): switch to github actions When this project was first started, Github Actions were not an option. Now that they are, and that teamcity is less accessible (lesser used, needs connection, ci link is not up to date), we are switching to gh actions. Fixes #279 --- .github/workflows/ci.yml | 86 +++++++++++++++++++ Gemfile | 2 +- README.md | 2 +- .../cockroachdb/schema_statements.rb | 2 +- .../adapters/postgresql/active_schema_test.rb | 4 +- .../cases/adapters/postgresql/postgis_test.rb | 6 +- .../connection_adapters/schema_cache_test.rb | 6 +- test/cases/fixtures_test.rb | 4 +- test/cases/helper_cockroachdb.rb | 6 +- test/cases/relation_test.rb | 2 +- test/excludes/PostgresqlRangeTest.rb | 41 +-------- test/support/rake_helpers.rb | 2 +- 12 files changed, 110 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..5c7e7a61 --- /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/README.md b/README.md index 9732bdf5..1fe67c07 100644 --- a/README.md +++ b/README.md @@ -321,7 +321,7 @@ p modified_fac.parse_wkt(wkt) #=> # ``` -Be careful when performing calculations on potentially invalid geometries, as the results might be nonsensical. For example, the area returned of an hourglass made of 2 equivalent triangles with a self-intersection in the middle is 0. +Be careful when performing calculations on potentially invalid geometries, as the results might be nonsensical. For example, the area returned of an hourglass made of 2 equivalent triangles with a self-intersection in the middle is 0. Note that when using the `spherical_factory`, there is a chance that valid geometries will be interpreted as invalid due to floating point issues with small geometries. diff --git a/lib/active_record/connection_adapters/cockroachdb/schema_statements.rb b/lib/active_record/connection_adapters/cockroachdb/schema_statements.rb index 0f399ed2..d7d8c42e 100644 --- a/lib/active_record/connection_adapters/cockroachdb/schema_statements.rb +++ b/lib/active_record/connection_adapters/cockroachdb/schema_statements.rb @@ -112,7 +112,7 @@ def new_column_from_field(table_name, field) # since type alone is not enough to format the column. # Ex. type_to_sql(:geography, limit: "Point,4326") # => "geography(Point,4326)" - # + # def type_to_sql(type, limit: nil, precision: nil, scale: nil, array: nil, **) # :nodoc: sql = \ case type.to_s 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/adapters/postgresql/postgis_test.rb b/test/cases/adapters/postgresql/postgis_test.rb index 4d19ee24..6d76e9b6 100644 --- a/test/cases/adapters/postgresql/postgis_test.rb +++ b/test/cases/adapters/postgresql/postgis_test.rb @@ -148,8 +148,10 @@ def test_spatial_factory_retrieval def test_point_to_json obj = klass.new assert_match(/"latlon":null/, obj.to_json) - obj.latlon = factory.point(1.0, 2.0) - assert_match(/"latlon":"POINT\s\(1\.0\s2\.0\)"/, obj.to_json) + obj.latlon = factory.point(1.1, 2.0) + # NOTE: rgeo opiniated in trimming numbers (e.g 1.0 would be trimmed to 1). + # We follow this convention here. + assert_match(/"latlon":"POINT\s\(1.1\s2\)"/, obj.to_json) end def test_custom_column 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/cases/fixtures_test.rb b/test/cases/fixtures_test.rb index f0a5698a..4a8cf08c 100644 --- a/test/cases/fixtures_test.rb +++ b/test/cases/fixtures_test.rb @@ -313,12 +313,13 @@ def before_setup firm_id bigint, firm_name character varying, credit_limit integer, + status string, #{'a' * max_identifier_length} integer ) ") Company.connection.drop_table :companies, if_exists: true - Company.connection.exec_query("CREATE SEQUENCE companies_nonstd_seq") + Company.connection.exec_query("CREATE SEQUENCE IF NOT EXISTS companies_nonstd_seq") Company.connection.exec_query(" CREATE TABLE companies ( id BIGINT PRIMARY KEY DEFAULT nextval('companies_nonstd_seq'), @@ -361,6 +362,7 @@ def teardown t.references :firm, index: false t.string :firm_name t.integer :credit_limit + t.string :status t.integer "a" * max_identifier_length end diff --git a/test/cases/helper_cockroachdb.rb b/test/cases/helper_cockroachdb.rb index ceac8cc3..2bcbfe24 100644 --- a/test/cases/helper_cockroachdb.rb +++ b/test/cases/helper_cockroachdb.rb @@ -1,5 +1,7 @@ -require 'bundler/setup' -Bundler.require :development +require 'bundler' +Bundler.setup + +require "minitest/excludes" # Turn on debugging for the test environment ENV['DEBUG_COCKROACHDB_ADAPTER'] = "1" diff --git a/test/cases/relation_test.rb b/test/cases/relation_test.rb index 9ed834a8..6d2d9eda 100644 --- a/test/cases/relation_test.rb +++ b/test/cases/relation_test.rb @@ -19,7 +19,7 @@ def test_relation_with_annotation_includes_comment_in_to_sql def test_relation_with_annotation_filters_sql_comment_delimiters post_with_annotation = Post.where(id: 1).annotate("**//foo//**") - assert_match %r{= '1' /\* foo \*/}, post_with_annotation.to_sql + assert_includes post_with_annotation.to_sql, "= '1' /* ** //foo// ** */" end def test_respond_to_for_non_selected_element diff --git a/test/excludes/PostgresqlRangeTest.rb b/test/excludes/PostgresqlRangeTest.rb index 695fbf29..53989f67 100644 --- a/test/excludes/PostgresqlRangeTest.rb +++ b/test/excludes/PostgresqlRangeTest.rb @@ -1,38 +1,3 @@ -exclude :test_create_int4range, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_timezone_awareness_tzrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_escaped_tsrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_update_tsrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_create_tsrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_infinity_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_update_int8range, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_ranges_correctly_escape_input, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_int8range_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_numrange_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_timezone_awareness_tsrange_preserve_usec, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_endless_range_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_int4range_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_update_daterange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_update_numrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_update_tsrange_preserve_usec, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_escaped_tstzrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_update_tstzrange_preserve_usec, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_ranges_correctly_unescape_output, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_where_by_attribute_with_range_in_array, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_tsrange_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_where_by_attribute_with_range, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_create_tsrange_preseve_usec, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_update_int4range, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_create_daterange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_create_tstzrange_preserve_usec, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_timezone_awareness_tsrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_daterange_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_update_all_with_ranges, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_custom_range_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_create_numrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_data_type_of_range_types, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_create_tstzrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_exclude_beginning_for_subtypes_without_succ_method_is_not_supported, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_tstzrange_values, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_update_tstzrange, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_create_int8range, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" -exclude :test_create_tsrange_preserve_usec, "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" +message = "CockroachDB doesn't support ranges. See https://github.com/cockroachdb/cockroach/issues/27791" +# No test is relevant in this class. +instance_methods.grep(/\Atest_/).each { exclude _1, message } diff --git a/test/support/rake_helpers.rb b/test/support/rake_helpers.rb index 09e61e1d..07a82807 100644 --- a/test/support/rake_helpers.rb +++ b/test/support/rake_helpers.rb @@ -12,7 +12,7 @@ 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(',').