-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update pinning for graphql 2.3...3 (#21)
* fix: update p * fix:updated to ~> * fix: printer * fix: updated with cops and print statements * fix: updated to 2-3 * Update version.rb * fix: gemspec * fix: gemspec * fix: cops * fix: updated graphql gemfile.lock * fix: add print_string explicitly * fix: update to 2.3 * fix: added fix and tests for usage_reporter * fix: update second gemfile.lock * Update spec/graphql/graphql-hive/usage_reporter_spec.rb Co-authored-by: Cassidy Scheffer <[email protected]> * fix: formatting * fix: updated to >= 2.3 --------- Co-authored-by: Cassidy Scheffer <[email protected]>
- Loading branch information
1 parent
25f080b
commit 01407d8
Showing
7 changed files
with
183 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
module Graphql | ||
module Hive | ||
VERSION = '0.3.3' | ||
VERSION = '0.3.4' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe GraphQL::Hive::UsageReporter do | ||
let(:subject) { described_class.instance } | ||
let(:client) { instance_double('Hive::Client') } | ||
let(:options) do | ||
{ | ||
logger: logger, | ||
buffer_size: 1 | ||
} | ||
end | ||
let(:logger) { instance_double('Logger') } | ||
|
||
before do | ||
allow(logger).to receive(:warn) | ||
allow(logger).to receive(:debug) | ||
end | ||
|
||
describe '#initialize' do | ||
it 'sets the instance' do | ||
expect(described_class.instance).to eq(nil) | ||
described_class.new(options, client) | ||
expect(described_class.instance).to_not eq(nil) | ||
end | ||
end | ||
|
||
describe '#add_operation' do | ||
it 'adds an operation to the queue' do | ||
operation = { operation: 'test' } | ||
described_class.new(options, client) | ||
subject.add_operation(operation) | ||
expect(subject.instance_variable_get(:@queue).pop).to eq(operation) | ||
end | ||
end | ||
|
||
describe '#on_exit' do | ||
it 'closes the queue and joins the thread' do | ||
described_class.new(options, client) | ||
expect(subject.instance_variable_get(:@queue)).to receive(:close) | ||
expect(subject.instance_variable_get(:@thread)).to receive(:join) | ||
subject.on_exit | ||
end | ||
end | ||
|
||
describe '#on_start' do | ||
it 'starts the thread' do | ||
described_class.new(options, client) | ||
expect(subject).to receive(:start_thread) | ||
subject.on_start | ||
end | ||
end | ||
|
||
describe '#start_thread' do | ||
it 'logs a warning if the thread is already alive' do | ||
described_class.new(options, client) | ||
subject.instance_variable_set(:@thread, Thread.new { p 'test' }) | ||
expect(logger).to receive(:warn) | ||
subject.on_start | ||
end | ||
end | ||
|
||
describe '#add_operation' do | ||
let(:timestamp) { 1_720_705_946_333 } | ||
let(:queries) { [] } | ||
let(:results) { [] } | ||
let(:duration) { 100_000 } | ||
let(:operation) do | ||
[timestamp, queries, results, duration] | ||
end | ||
let(:schema) do | ||
GraphQL::Schema.from_definition('type Query { test: String }') | ||
end | ||
let(:query_string) { 'query TestingHive { test }' } | ||
|
||
it 'adds an operation to the buffer' do | ||
described_class.new(options, client) | ||
subject.add_operation(operation) | ||
expect(subject.instance_variable_get(:@queue).pop).to eq(operation) | ||
end | ||
|
||
context 'successful operation' do | ||
let(:options) do | ||
{ logger: logger, buffer_size: 2 } | ||
end | ||
let(:queries) do | ||
[GraphQL::Query.new(schema, query_string, variables: {})] | ||
end | ||
let(:results) do | ||
[GraphQL::Query::Result.new(query: queries.first, values: { 'data' => { 'test' => 'test' } })] | ||
end | ||
|
||
before do | ||
allow(client).to receive(:send) | ||
end | ||
|
||
it 'processes the operations if the buffer is full' do | ||
described_class.new(options, client) | ||
subject.add_operation(operation) | ||
|
||
# call process_operation with send | ||
subject.send(:process_operations, [operation]) | ||
expect(client).to have_received(:send).with( | ||
'/usage', | ||
{ | ||
map: { '8b8412ce86f3ea7accb931b1a5de335d' => | ||
{ | ||
fields: %w[Query Query.test], | ||
operation: "query TestingHive {\n test\n}", | ||
operationName: 'TestingHive' | ||
} }, | ||
operations: [ | ||
{ | ||
execution: { duration: 100_000, errors: [], errorsTotal: 0, ok: true }, | ||
operationMapKey: '8b8412ce86f3ea7accb931b1a5de335d', | ||
timestamp: 1_720_705_946_333 | ||
} | ||
], | ||
size: 1 | ||
}, | ||
:usage | ||
) | ||
end | ||
end | ||
end | ||
end |