Stabilize flaky remoteStorage Redis spec
"stores a token in redis" asserted an exact count of Redis keys for the user, but database cleanup only covers SQL and Redis keys accumulate across examples and spec files. It also relied on a previously-run example having created the authorization, so it failed depending on test order and leftover state. Clear the authorizations:* namespace before each example in the #create group, create the authorization under test, and assert on its specific token key instead of a global count.
This commit is contained in:
1 file changed
+3
-3
@@ -11,6 +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:*") }
|
||||
|
||||
@@ -27,10 +28,9 @@ RSpec.describe RemoteStorageAuthorization, type: :model do
|
||||
end
|
||||
|
||||
it "stores a token in redis" do
|
||||
user_auth_keys = redis_rs.keys("authorizations:#{user.cn}:*")
|
||||
expect(user_auth_keys.length).to eq(1)
|
||||
auth
|
||||
|
||||
authorizations = redis_rs.smembers(user_auth_keys.first)
|
||||
authorizations = redis_rs.smembers("authorizations:#{user.cn}:#{auth.token}")
|
||||
expect(authorizations.sort).to eq(%w(documents photos contacts:rw videos:r tasks/work:r).sort)
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user