Skip to content

Commit

Permalink
use sized queue
Browse files Browse the repository at this point in the history
  • Loading branch information
cassidycodes committed Nov 1, 2024
1 parent 0bb3654 commit 9b66230
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 126 deletions.
26 changes: 0 additions & 26 deletions lib/graphql-hive/bounded_queue.rb

This file was deleted.

10 changes: 4 additions & 6 deletions lib/graphql-hive/usage_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require "digest"
require "graphql-hive/analyzer"
require "graphql-hive/printer"
require "graphql-hive/bounded_queue"

module GraphQL
class Hive < GraphQL::Tracing::PlatformTracing
Expand All @@ -21,16 +20,15 @@ def initialize(options, client)
@client = client
@options_mutex = Mutex.new
@sampler = Sampler.new(options[:collect_usage_sampling], options[:logger]) # NOTE: logs for deprecated field
@queue = BoundedQueue.new(
bound: options[:queue_size],
logger: options[:logger]
)
@queue = Thread::SizedQueue.new(options[:queue_size])

start_thread
end

def add_operation(operation)
@queue.push(operation)
@queue.push(operation, true)
rescue ThreadError
@options[:logger].error("SizedQueue is full, discarding operation. Size: #{@queue.size}, Max: #{@queue.max}")
end

def on_exit
Expand Down
93 changes: 0 additions & 93 deletions spec/graphql/graphql-hive/bounded_queue_spec.rb

This file was deleted.

13 changes: 12 additions & 1 deletion spec/graphql/graphql-hive/usage_reporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
expect(usage_reporter_instance.instance_variable_get(:@client)).to eq(client)

expect(usage_reporter_instance.instance_variable_get(:@options_mutex)).to be_an_instance_of(Mutex)
expect(usage_reporter_instance.instance_variable_get(:@queue)).to be_an_instance_of(GraphQL::Hive::BoundedQueue)
expect(usage_reporter_instance.instance_variable_get(:@queue)).to be_an_instance_of(Thread::SizedQueue)
expect(usage_reporter_instance.instance_variable_get(:@sampler)).to be_an_instance_of(GraphQL::Hive::Sampler)
end
end
Expand All @@ -44,6 +44,17 @@
usage_reporter_instance.add_operation(operation)
expect(usage_reporter_instance.instance_variable_get(:@queue).pop).to eq(operation)
end

describe "when the queue is full" do
let(:options) { {logger: logger, buffer_size: 1, queue_size: 1} }

it "logs an error" do
allow(logger).to receive(:error)
usage_reporter_instance.add_operation("operation 1")
usage_reporter_instance.add_operation("operation 2")
expect(logger).to have_received(:error)
end
end
end

describe "#on_exit" do
Expand Down

0 comments on commit 9b66230

Please sign in to comment.