Tôi đang cố gắng viết một thông số kỹ thuật để kiểm tra chức năng thử lại của quá trình thử lại và tôi dường như không thể lấy các phép thử để đạt được giá trị của binding.pry một cách chính xác. Có cách nào để kiểm tra chức năng này bằng cách sử dụng rspec 3 để tôi có thể xác minh chúng hoạt động như dự định không?Làm thế nào để kiểm tra thử lại và thất bại trong resque-retry và Rails 4?
Đây là thông số yêu cầu và tôi đang cố gắng mô phỏng yêu cầu trực tiếp thông qua đồ đạc, nhưng cho dù tôi cố gắng làm gì, dường như tôi không thể thử lại công việc.
gem 'resque', require: 'resque/server'
gem 'resque-web', require: 'resque_web'
gem 'resque-scheduler'
gem 'resque-retry'
gem 'resque-lock-timeout'
Tôi đang sử dụng resque_rspec và thử số testing strategy này.
phần Spec
it 'retries it' do
stub_request(:any, /.*api.bigcartel.*/).to_return(body: '{}', status: 200)
@order_shipped_json['order']['originator_id'] = @provider_order
post "/hook/shops/#{@shop.id}", @order_shipped_json.to_json, format: :json
ResqueSpec.perform_all(queue_name)
???
end
Queue Job Modules
class QueueHook
extend Resque::Plugins::LockTimeout
extend Resque::Plugins::Retry
extend QueueLock
extend QueueLogger
@queue = AppSettings.queues[:hook_queue_name].to_sym
@lock_timeout = 600
@retry_exceptions = [QueueError::LockFailed]
@retry_limit = 600
@retry_delay = 1
class << self
def perform(web_hook_payload_id, _whiplash_customer_id)
ActiveRecord::Base.clear_active_connections!
@web_hook_payload = WebHookPayload.find(web_hook_payload_id)
klass_constructor
@hook.process_event
end
def identifier(_web_hook_payload_id, whiplash_customer_id)
"lock:integration_hook:#{whiplash_customer_id}"
end
def after_perform_delete_webhook(_web_hook_payload_id, _whiplash_customer_id)
@web_hook_payload.destroy
end
private
...
end
end
Queue Job
module QueueLogger
def before_perform_log_job(*args)
Rails.logger.info "[Resque][#{self}] running with #{args.inspect}..."
end
def on_failure_log_job(*args)
message = "[Resque][#{self}] failed with #{args.inspect}..."
run_counters
Rails.logger.info message_builder(message)
end
private
def run_counters
@num_attempts += retry_attempt
@all_attempts += retry_limit
end
def message_builder(message)
return message unless @num_attempts
return message += " Retrying (attempt ##{@num_attempts + 1})" if @num_attempts < @all_attempts
message += ' Giving up.'
message
end
end
module QueueLock
def loner_enqueue_failed(*args)
Rails.logger.info "[Resque][#{self}] is already enqueued: #{args.inspect}..."
end
def lock_failed(*)
raise QueueError::LockFailed
end
end
Bạn phải sử dụng trình xử lý ngoại lệ. – user1735921
bạn có thông số mẫu không? –
không sử dụng thử lại giải cứu, bắt ngoại lệ và thử lại trong mã – user1735921