Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add Tests for GraphQL C Parser #773

Merged
merged 6 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions instrumentation/graphql/Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,39 @@
#
# SPDX-License-Identifier: Apache-2.0

appraise 'graphql-1.13' do
# Max compatible version of 1.x
appraise 'graphql-1.x' do
gem 'graphql', '~> 1.13'
end

appraise 'graphql-2.0.17' do
gem 'graphql', '2.0.17'
end

# A bug was introduced in 2.0.18 that was fixed in 2.0.19
appraise 'graphql-2.0.18' do
gem 'graphql', '2.0.18'
end

appraise 'graphql-2.x' do
gem 'graphql', '>= 2.0.18', '< 3.0.0'
# Max compatible version of 2.0.x
appraise 'graphql-2.0' do
gem 'graphql', '~> 2.0.27'
end

# Max compatible version of 2.1.x
appraise 'graphql-2.1' do
gem 'graphql', '~> 2.1.8'
end

appraise 'graphql-c_parser-2.2.x' do
gem 'graphql', '~> 2.2.1'
gem 'graphql-c_parser', '~> 1.0.7'
end

appraise 'graphql-2.2.x' do
gem 'graphql', '~> 2.2.1', '< 3.0.0'
Comment on lines +32 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want to have one run against latest?

Perhaps could match the styles of other appraisals to the same effect.

Suggested change
appraise 'graphql-2.2.x' do
gem 'graphql', '~> 2.2.1', '< 3.0.0'
# Max compatible version of 2.2.x
appraise 'graphql-2.2' do
gem 'graphql', '~> 2.2.1'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Major version changes have been difficult for us to test using appraisals, while maintaining minor versions.

We used to have canary builds that rain on unpinned versions of gems but I couldn't keep up with them so I disabled those builds.

I will however add unpinned versions of the gem to this PR and see if that puts us in a better place for the future canary work.

Copy link
Collaborator Author

@arielvalentin arielvalentin Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added here: 4451a54

end

appraise 'graphql-c_parser-latest' do
gem 'graphql-c_parser'
end

appraise 'graphql-latest' do
gem 'graphql'
end
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
'graphql.execute_multiplex'
]

expected_spans.delete('graphql.lex') unless trace_lex_supported?

expected_result = {
'simpleField' => 'Hello.',
'resolvedField' => { 'originalValue' => 'testing=1', 'uppercasedValue' => 'TESTING=1' }
Expand Down Expand Up @@ -103,7 +105,7 @@
it 'traces the provided schemas' do
SomeOtherGraphQLAppSchema.execute('query SimpleQuery{ __typename }')

_(spans.size).must_equal(8)
_(spans.select { |s| s.name.start_with?('graphql.') }).wont_be(:empty?)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like looking for the name rather than the quantity. Nice update.

end

it 'does not trace all schemas' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'graphql.execute_query_lazy',
'graphql.execute_multiplex'
]
expected_spans.delete('graphql.lex') unless trace_lex_supported?

expected_result = {
'simpleField' => 'Hello.',
Expand Down Expand Up @@ -102,7 +103,7 @@

it 'traces the provided schemas' do
SomeOtherGraphQLAppSchema.execute('query SimpleQuery{ __typename }')
_(spans.size).must_equal(8)
_(spans.select { |s| s.name.start_with?('graphql.') }).wont_be(:empty?)
end

it 'does not trace all schemas' do
Expand Down
9 changes: 9 additions & 0 deletions instrumentation/graphql/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,12 @@ def uses_platform_interfaces?
def gem_version
Gem::Version.new(GraphQL::VERSION)
end

# When tracing, is the parser expected to call `lex` before `parse`
def trace_lex_supported?
return @trace_lex_supported if defined?(@trace_lex_supported)

# In GraphQL 2.2, the default parser was changed such that `lex` is no longer called
@trace_lex_supported = Gem::Requirement.new('< 2.2').satisfied_by?(Gem::Version.new(GraphQL::VERSION)) \
|| (defined?(GraphQL::CParser) == 'constant')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anything result in require "graphql/c_parser" such that this is true when the gem is installed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test helper uses bundler require, which will load all of the declared gems by default before running any tests.

In this case the Gemfile requires the graphql-c_parser file in the gems' lib directory, which requires graphql/c_parser... then turtles all the way down.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end