@@ -12,17 +12,40 @@ def int
1212 end
1313 end
1414
15+ class DummyEngine
16+ def self . dispatched_events
17+ @dispatched_events ||= [ ]
18+ end
19+
20+ def self . instrument ( event , payload )
21+ dispatched_events << [ event , payload ]
22+ yield if block_given?
23+ end
24+ end
25+
26+ module OtherTrace
27+ def execute_query ( query :)
28+ query . context [ :other_trace_ran ] = true
29+ super
30+ end
31+ end
32+
1533 class Schema < GraphQL ::Schema
1634 query Query
35+ trace_with OtherTrace
36+ trace_with GraphQL ::Tracing ::NotificationsTrace , engine : DummyEngine
1737 end
1838 end
1939
20- describe "Observing" do
21- it "dispatches the event to the notifications engine with suffixed key" do
22- dispatched_events = trigger_fake_notifications_tracer ( NotificationsTraceTest :: Schema ) . to_h
40+ before do
41+ NotificationsTraceTest :: DummyEngine . dispatched_events . clear
42+ end
2343
24- assert dispatched_events . length > 0
2544
45+ describe "Observing" do
46+ it "dispatches the event to the notifications engine with suffixed key" do
47+ NotificationsTraceTest ::Schema . execute "query X { int }"
48+ dispatched_events = NotificationsTraceTest ::DummyEngine . dispatched_events . to_h
2649 expected_event_keys = [
2750 'execute_multiplex.graphql' ,
2851 'analyze_multiplex.graphql' ,
@@ -43,20 +66,10 @@ class Schema < GraphQL::Schema
4366 assert payload . is_a? ( Hash )
4467 end
4568 end
46- end
47-
48- def trigger_fake_notifications_tracer ( schema )
49- dispatched_events = [ ]
50- engine = Object . new
5169
52- engine . define_singleton_method ( :instrument ) do | event , payload , & blk |
53- dispatched_events << [ event , payload ]
54- blk . call if blk
70+ it "works with other tracers" do
71+ res = NotificationsTraceTest :: Schema . execute "query X { int }"
72+ assert res . context [ :other_trace_ran ]
5573 end
56-
57- schema . trace_with GraphQL ::Tracing ::NotificationsTrace , engine : engine
58- schema . execute "query X { int }"
59-
60- dispatched_events
6174 end
6275end
0 commit comments