debian-mirror-gitlab/spec/lib/gitlab/graphql/query_analyzers/logger_analyzer_spec.rb

50 lines
1.8 KiB
Ruby
Raw Normal View History

2019-09-04 21:01:54 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer do
2021-04-29 21:17:54 +05:30
let(:initial_value) { analyzer.initial_value(query) }
let(:analyzer) { described_class.new }
let(:query) { GraphQL::Query.new(GitlabSchema, document: document, context: {}, variables: { body: "some note" }) }
let(:document) do
GraphQL.parse <<-GRAPHQL
mutation createNote($body: String!) {
createNote(input: {noteableId: "1", body: $body}) {
note {
id
2021-02-04 15:43:07 +05:30
}
}
2021-04-29 21:17:54 +05:30
}
GRAPHQL
end
2021-02-04 15:43:07 +05:30
2021-04-17 20:07:23 +05:30
describe '#final_value' do
let(:monotonic_time_before) { 42 }
let(:monotonic_time_after) { 500 }
let(:monotonic_time_duration) { monotonic_time_after - monotonic_time_before }
2021-04-29 21:17:54 +05:30
let(:memo) { initial_value }
subject(:final_value) { analyzer.final_value(memo) }
before do
RequestStore.store[:graphql_logs] = nil
2021-04-17 20:07:23 +05:30
allow(GraphQL::Analysis).to receive(:analyze_query).and_return([4, 2, [[], []]])
allow(Gitlab::Metrics::System).to receive(:monotonic_time).and_return(monotonic_time_before, monotonic_time_after)
allow(Gitlab::GraphqlLogger).to receive(:info)
2021-04-29 21:17:54 +05:30
end
2021-04-17 20:07:23 +05:30
2021-04-29 21:17:54 +05:30
it 'inserts duration in seconds to memo and sets request store' do
expect { final_value }.to change { memo[:duration_s] }.to(monotonic_time_duration)
2021-12-11 22:18:48 +05:30
.and change { RequestStore.store[:graphql_logs] }.to([{
complexity: 4,
depth: 2,
operation_name: query.operation_name,
used_deprecated_fields: [],
used_fields: [],
variables: { body: "[FILTERED]" }.to_s
}])
2021-04-17 20:07:23 +05:30
end
end
2019-09-04 21:01:54 +05:30
end