2020-05-21 09:08:04 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require 'rspec-parameterized'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::Instrumentation::RedisInterceptor, :clean_gitlab_redis_shared_state, :request_store do
|
2020-05-21 09:08:04 +00:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
describe 'read and write' do
|
|
|
|
where(:setup, :command, :expect_write, :expect_read) do
|
|
|
|
# The response is 'OK', the request size is the combined size of array
|
|
|
|
# elements. Exercise counting of a status reply.
|
|
|
|
[] | [:set, 'foo', 'bar'] | 3 + 3 + 3 | 2
|
|
|
|
|
|
|
|
# The response is 1001, so 4 bytes. Exercise counting an integer reply.
|
|
|
|
[[:set, 'foobar', 1000]] | [:incr, 'foobar'] | 4 + 6 | 4
|
|
|
|
|
|
|
|
# Exercise counting empty multi bulk reply
|
|
|
|
[] | [:hgetall, 'foobar'] | 7 + 6 | 0
|
|
|
|
|
|
|
|
# Hgetall response length is combined length of keys and values in the
|
|
|
|
# hash. Exercises counting of a multi bulk reply
|
|
|
|
[[:hset, 'myhash', 'field', 'hello world']] | [:hgetall, 'myhash'] | 7 + 6 | 5 + 11
|
|
|
|
|
|
|
|
# Exercise counting of a bulk reply
|
|
|
|
[[:set, 'foo', 'bar' * 100]] | [:get, 'foo'] | 3 + 3 | 3 * 100
|
2020-06-15 21:08:35 +00:00
|
|
|
|
|
|
|
# Nested array response: ['123456-89', ['foo', 'bar']]
|
|
|
|
[[:xadd, 'mystream', '123456-89', 'foo', 'bar']] | [:xrange, 'mystream', '-', '+'] | 6 + 8 + 1 + 1 | 9 + 3 + 3
|
2020-05-21 09:08:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it 'counts bytes read and written' do
|
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
|
|
|
setup.each { |cmd| redis.call(cmd) }
|
|
|
|
RequestStore.clear!
|
|
|
|
redis.call(command)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(Gitlab::Instrumentation::Redis.read_bytes).to eq(expect_read)
|
|
|
|
expect(Gitlab::Instrumentation::Redis.write_bytes).to eq(expect_write)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|