From e3d5185c54033a8383563eaa5783d006c02a2094 Mon Sep 17 00:00:00 2001 From: Luis Caparroz Date: Tue, 30 Jan 2024 18:10:22 +0100 Subject: [PATCH 1/6] Improve RMT::Lockfile#lock condition for SQLite3 When running tests, the `yield and return if *` statement seems to not be working properly; even when the condition is true, it would not return. --- lib/rmt/lockfile.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/rmt/lockfile.rb b/lib/rmt/lockfile.rb index 4fb6bf868..9b1242aee 100644 --- a/lib/rmt/lockfile.rb +++ b/lib/rmt/lockfile.rb @@ -3,7 +3,10 @@ class RMT::Lockfile class << self def lock(lock_name = nil) - yield and return if ActiveRecord::Base.connection.adapter_name != 'Mysql2' + if ActiveRecord::Base.connection.adapter_name != 'Mysql2' + yield + return + end lock_name = ['rmt-cli', lock_name].compact.join('-') From 62b0b58ea097f92eb681f75852dffdede4a81d44 Mon Sep 17 00:00:00 2001 From: Luis Caparroz Date: Tue, 30 Jan 2024 18:36:39 +0100 Subject: [PATCH 2/6] Add helper for not running lock tests with sqlite --- spec/support/cli_helpers.rb | 4 ++++ spec/support/shared_examples/cli.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/support/cli_helpers.rb b/spec/support/cli_helpers.rb index 7dd870abf..f0e961e27 100644 --- a/spec/support/cli_helpers.rb +++ b/spec/support/cli_helpers.rb @@ -12,3 +12,7 @@ def silence_stdout def file_human_size(size_in_bytes) ActiveSupport::NumberHelper.number_to_human_size(size_in_bytes) end + +def running_mysql + ActiveRecord::Base.connection.adapter_name == 'Mysql2' +end diff --git a/spec/support/shared_examples/cli.rb b/spec/support/shared_examples/cli.rb index 57e38de8f..3b2ec407b 100644 --- a/spec/support/shared_examples/cli.rb +++ b/spec/support/shared_examples/cli.rb @@ -17,7 +17,7 @@ end shared_examples 'handles lockfile exception' do - context 'with existing lockfile' do + context 'with existing lockfile', if: running_mysql do before do allow(RMT::Lockfile).to receive(:obtain_lock).and_return(false) end From 03e72e5b960b9a144e6bc3ef12fbc00b5a07c813 Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Thu, 1 Feb 2024 16:07:02 +0100 Subject: [PATCH 3/6] add sqlite3-devel dev dependency --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 697f53540..abf464ccd 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Please view our [guide](docs/installation.md) to assist you in the RMT installat 1. Install the system dependencies: ``` - sudo zypper in libxml2-devel libxslt-devel libmariadb-devel gcc + sudo zypper in libxml2-devel libxslt-devel libmariadb-devel sqlite3-devel gcc ``` 2. Install the ruby version specified in the `.ruby-version` [file](.ruby-version). 3. Install and setup the database: From d8752028b6be9ba18640d09a06b0b2d865f59c27 Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Mon, 12 Feb 2024 15:29:14 +0100 Subject: [PATCH 4/6] install sqlite3-devel in container image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1af512726..2861e54c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM opensuse/leap:15.3 RUN zypper --non-interactive install --no-recommends \ timezone wget gcc-c++ libffi-devel git-core zlib-devel \ - libxml2-devel libxslt-devel cron libmariadb-devel mariadb-client \ + libxml2-devel libxslt-devel cron libmariadb-devel mariadb-client sqlite3-devel \ vim ruby2.5 ruby2.5-devel ruby2.5-rubygem-bundler SUSEConnect && \ zypper --non-interactive install -t pattern devel_basis && \ update-alternatives --install /usr/bin/bundle bundle /usr/bin/bundle.ruby2.5 5 && \ From d993c4bb9d130ca5c17e2fa9cabfa833bf254213 Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Mon, 12 Feb 2024 15:31:43 +0100 Subject: [PATCH 5/6] update to current schema rev --- db/schema.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 1f3795dbe..a1db7d82f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_08_14_105634) do +ActiveRecord::Schema.define(version: 2024_01_29_140413) do create_table "activations", charset: "utf8", force: :cascade do |t| t.bigint "service_id", null: false From c76e37227d97b7aa76507e9a8aba4d3680d5d274 Mon Sep 17 00:00:00 2001 From: Thomas Schmidt Date: Mon, 12 Feb 2024 15:51:50 +0100 Subject: [PATCH 6/6] cover sqlite3 case in lockfile test -> 100% coverage --- .rubocop.yml | 3 +++ spec/lib/rmt/lockfile_spec.rb | 7 +++++++ spec/lib/suse/connect/api_spec.rb | 2 -- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ccd2a7a06..1ec897b79 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -47,3 +47,6 @@ Style/FormatStringToken: Style/OpenStructUse: Enabled: false + +RSpec/MessageChain: + Enabled: false diff --git a/spec/lib/rmt/lockfile_spec.rb b/spec/lib/rmt/lockfile_spec.rb index f7ac31acb..d1b86f968 100644 --- a/spec/lib/rmt/lockfile_spec.rb +++ b/spec/lib/rmt/lockfile_spec.rb @@ -51,5 +51,12 @@ ) end end + + context 'with sqlite backend' do + it 'yields block' do + allow(ActiveRecord::Base).to receive_message_chain(:connection, :adapter_name).and_return('sqlite3') + expect(lock).to eq nil + end + end end end diff --git a/spec/lib/suse/connect/api_spec.rb b/spec/lib/suse/connect/api_spec.rb index 865da6418..b73cfe669 100644 --- a/spec/lib/suse/connect/api_spec.rb +++ b/spec/lib/suse/connect/api_spec.rb @@ -44,7 +44,6 @@ end end - # rubocop:disable RSpec/MessageChain describe '#connect_api' do subject(:method_call) { api_client.send(:connect_api) } @@ -77,7 +76,6 @@ end end end - # rubocop:enable RSpec/MessageChain context 'api requests' do before do