Sha256: 02aadc1de4b1635874be0b9157d7fdfc983f47055b2121279c776b384585a9a2

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

require "#{File.dirname(__FILE__)}/../spec_helper"

RSpec.describe "ActiveJobs perform metrics", type: :request do
  let(:tags_middleware) do
    lambda do |tags|
      tags.merge(tags_middleware: :tags_middleware)
    end
  end
  before do
    allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_environments).and_return(%w[development])
    allow_any_instance_of(ActionDispatch::Request).to receive(:request_id).and_return(:request_id)
    allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:application_name).and_return(:app_name)
    allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:tags_middleware).and_return(tags_middleware)
  end

  it "writes metric" do
    perform_enqueued_jobs do
      get "/metrics"
    end

    expect_metric(
      tags:   a_hash_including(
        hook:  "perform",
        state: "succeeded",
        job:   "MetricJob",
        queue: "default"
      ),
      values: a_hash_including(
        value: be_between(0, 30)
      )
    )
  end

  it "includes correct timestamps" do
    travel_to Time.zone.local(2018, 1, 1, 9, 0, 0)

    perform_enqueued_jobs do
      get "/metrics"
    end

    expect_metric(
      tags:      a_hash_including(
        hook:     "perform"
      ),
      timestamp: 1_514_797_200
    )
  end

  it "does not write metric when hook is ignored" do
    allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["perform.active_job"])

    perform_enqueued_jobs do
      get "/metrics"
    end

    expect_no_metric(
      tags: a_hash_including(
        hook:     "perform"
      )
    )
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
influxdb-rails-1.0.3 spec/requests/active_job_perform_metrics_spec.rb
influxdb-rails-1.0.2 spec/requests/active_job_perform_metrics_spec.rb