-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for memory and redis storage
- Loading branch information
Showing
5 changed files
with
90 additions
and
7 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
47 changes: 47 additions & 0 deletions
47
spec/graphql/tracing/perfetto_sampler/backend_assertions.rb
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,47 @@ | ||
# frozen_string_literal: true | ||
|
||
module GraphQLTracingPerfettoSamplerBackendAssertions | ||
def self.included(child_class) | ||
child_class.instance_eval do | ||
describe "BackendAssertions" do | ||
before do | ||
@backend.delete_all_traces | ||
end | ||
|
||
it "can save, retreive, list, and delete traces" do | ||
data = SecureRandom.bytes(1000) | ||
trace_id = @backend.save_trace( | ||
"GetStuff", | ||
100.56, | ||
Time.utc(2024, 01, 01, 04, 44, 33, 695), | ||
data | ||
) | ||
|
||
trace = @backend.find_trace(trace_id) | ||
assert_kind_of GraphQL::Tracing::PerfettoSampler::StoredTrace, trace | ||
assert_equal "GetStuff", trace.operation_name | ||
assert_equal 100.56, trace.duration_ms | ||
assert_equal "2024-01-01 04:44:33.000", trace.timestamp.utc.strftime("%Y-%m-%d %H:%M:%S.%L") | ||
assert_equal data, trace.trace_data | ||
|
||
|
||
@backend.save_trace( | ||
"GetOtherStuff", | ||
200.16, | ||
Time.utc(2024, 01, 03, 04, 44, 33, 695), | ||
data | ||
) | ||
|
||
assert_equal ["GetStuff", "GetOtherStuff"], @backend.traces.map(&:operation_name) | ||
|
||
@backend.delete_trace(trace_id) | ||
|
||
assert_equal ["GetOtherStuff"], @backend.traces.map(&:operation_name) | ||
|
||
@backend.delete_all_traces | ||
assert_equal [], @backend.traces | ||
end | ||
end | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
spec/graphql/tracing/perfetto_sampler/memory_backend_spec.rb
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,11 @@ | ||
# frozen_string_literal: true | ||
require "spec_helper" | ||
require_relative "./backend_assertions" | ||
|
||
describe GraphQL::Tracing::PerfettoSampler::MemoryBackend do | ||
include GraphQLTracingPerfettoSamplerBackendAssertions | ||
|
||
before do | ||
@backend = GraphQL::Tracing::PerfettoSampler::MemoryBackend.new | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
spec/graphql/tracing/perfetto_sampler/redis_backend_spec.rb
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,13 @@ | ||
# frozen_string_literal: true | ||
require "spec_helper" | ||
require_relative "./backend_assertions" | ||
|
||
if defined?(::Redis) | ||
describe GraphQL::Tracing::PerfettoSampler::RedisBackend do | ||
include GraphQLTracingPerfettoSamplerBackendAssertions | ||
|
||
before do | ||
@backend = GraphQL::Tracing::PerfettoSampler::RedisBackend.new(redis: Redis.new) | ||
end | ||
end | ||
end |