@@ -47,14 +47,19 @@ def self.default_info
4747 # @param payload_converter [Converters::PayloadConverter] Value for {Activity::Context#payload_converter}.
4848 # @param logger [Logger] Value for {Activity::Context#logger}.
4949 # @param activity_executors [Hash<Symbol, Worker::ActivityExecutor>] Executors that activities can run within.
50+ # @param metric_meter [Metric::Meter, nil] Value for {Activity::Context#metric_meter}, or nil to raise when
51+ # called.
52+ # @param client [Client, nil] Value for {Activity::Context#client}, or nil to raise when called.
5053 def initialize (
5154 info : ActivityEnvironment . default_info ,
5255 on_heartbeat : nil ,
5356 cancellation : Cancellation . new ,
5457 worker_shutdown_cancellation : Cancellation . new ,
5558 payload_converter : Converters ::PayloadConverter . default ,
5659 logger : Logger . new ( nil ) ,
57- activity_executors : Worker ::ActivityExecutor . defaults
60+ activity_executors : Worker ::ActivityExecutor . defaults ,
61+ metric_meter : nil ,
62+ client : nil
5863 )
5964 @info = info
6065 @on_heartbeat = on_heartbeat
@@ -63,6 +68,8 @@ def initialize(
6368 @payload_converter = payload_converter
6469 @logger = logger
6570 @activity_executors = activity_executors
71+ @metric_meter = metric_meter
72+ @client = client
6673 end
6774
6875 # Run an activity and returns its result or raises its exception.
@@ -86,7 +93,9 @@ def run(activity, *args)
8693 cancellation : @cancellation ,
8794 worker_shutdown_cancellation : @worker_shutdown_cancellation ,
8895 payload_converter : @payload_converter ,
89- logger : @logger
96+ logger : @logger ,
97+ metric_meter : @metric_meter ,
98+ client : @client
9099 ) )
91100 queue . push ( [ defn . proc . call ( *args ) , nil ] )
92101 rescue Exception => e # rubocop:disable Lint/RescueException Intentionally capturing all exceptions
@@ -113,7 +122,9 @@ def initialize( # rubocop:disable Lint/MissingSuper
113122 cancellation :,
114123 worker_shutdown_cancellation :,
115124 payload_converter :,
116- logger :
125+ logger :,
126+ metric_meter :,
127+ client :
117128 )
118129 @info = info
119130 @instance = instance
@@ -122,12 +133,24 @@ def initialize( # rubocop:disable Lint/MissingSuper
122133 @worker_shutdown_cancellation = worker_shutdown_cancellation
123134 @payload_converter = payload_converter
124135 @logger = logger
136+ @metric_meter = metric_meter
137+ @client = client
125138 end
126139
127140 # @!visibility private
128141 def heartbeat ( *details )
129142 @on_heartbeat &.call ( details )
130143 end
144+
145+ # @!visibility private
146+ def metric_meter
147+ @metric_meter or raise 'No metric meter configured in this test environment'
148+ end
149+
150+ # @!visibility private
151+ def client
152+ @client or raise 'No client configured in this test environment'
153+ end
131154 end
132155
133156 private_constant :Context
0 commit comments