From 1ac5c7725ad02fc26b681680c4f3d5f4cb8282d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Tue, 3 Nov 2026 08:31:26 +0400 Subject: [PATCH] Isolate remoteStorage Redis specs from concurrent runs The specs deleted a global authorizations:* pattern from the shared test Redis DB, so concurrent test processes could wipe each other's keys mid-example, causing intermittent empty/mismatched set failures. Drop all global pattern deletes and the now-unused redis_rs_delete_keys helper. Each spec now reads or asserts only the exact key derived from its own random token, so runs can no longer interfere regardless of ordering or concurrency. Also fixes a vacuous assertion in the #destroy spec, which checked authorizations::* (never matching the keys, which use user.cn), to assert the exact key is gone. --- spec/models/remote_storage_authorization_spec.rb | 10 +--------- spec/support/helpers/redis_helper.rb | 5 ----- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/spec/models/remote_storage_authorization_spec.rb b/spec/models/remote_storage_authorization_spec.rb index 1791ab2..378ebb6 100644 --- a/spec/models/remote_storage_authorization_spec.rb +++ b/spec/models/remote_storage_authorization_spec.rb @@ -11,9 +11,7 @@ RSpec.describe RemoteStorageAuthorization, type: :model do end describe "#create" do - before(:each) { redis_rs_delete_keys("authorizations:*") } after(:each) { clear_enqueued_jobs } - after(:all) { redis_rs_delete_keys("authorizations:*") } let(:auth) do user.remote_storage_authorizations.create!( @@ -49,7 +47,6 @@ RSpec.describe RemoteStorageAuthorization, type: :model do describe "#destroy" do after(:each) { clear_enqueued_jobs } - after(:all) { redis_rs_delete_keys("authorizations:*") } it "removes the token from redis" do auth = user.remote_storage_authorizations.create!( @@ -59,7 +56,7 @@ RSpec.describe RemoteStorageAuthorization, type: :model do ) auth.destroy! - expect(redis_rs.keys("authorizations:#{user.address}:*")).to be_empty + expect(redis_rs.exists?("authorizations:#{user.cn}:#{auth.token}")).to be(false) end context "with expiry set" do @@ -79,8 +76,6 @@ RSpec.describe RemoteStorageAuthorization, type: :model do describe "#find_or_create_web_app" do context "with origin that looks hosted" do - after(:all) { redis_rs_delete_keys("authorizations:*") } - let(:auth) do user.remote_storage_authorizations.create!( permissions: %w(documents:rw), @@ -173,8 +168,6 @@ RSpec.describe RemoteStorageAuthorization, type: :model do end describe "#launch_url" do - after(:all) { redis_rs_delete_keys("authorizations:*") } - context "without start URL" do before do AppCatalog::WebApp.create!( @@ -250,7 +243,6 @@ RSpec.describe RemoteStorageAuthorization, type: :model do include ActiveJob::TestHelper after(:each) { clear_enqueued_jobs } - after(:all) { redis_rs_delete_keys("authorizations:*") } before { allow(user).to receive(:display_name).and_return("Jimmy") } diff --git a/spec/support/helpers/redis_helper.rb b/spec/support/helpers/redis_helper.rb index 2571fce..f81b2ae 100644 --- a/spec/support/helpers/redis_helper.rb +++ b/spec/support/helpers/redis_helper.rb @@ -1,8 +1,3 @@ def redis_rs @redis_rs ||= Redis.new(url: Setting.rs_redis_url) end - -def redis_rs_delete_keys(pattern) - keys = redis_rs.keys(pattern) - redis_rs.del(*keys) -end