Sha256: c91ce75056d22be87042ecc97a150e749096a0cdaf48b5fdcc8e640acbad0693

Contents?: true

Size: 1.53 KB

Versions: 29

Compression:

Stored size: 1.53 KB

Contents

ENV['SKIP_RAILS'] = 'true'
require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))

class NewRelic::Agent::WorkerLoopTest < Test::Unit::TestCase
  def setup
    @log = ""
    @logger = Logger.new(StringIO.new(@log))
    @worker_loop = NewRelic::Agent::WorkerLoop.new
    @worker_loop.stubs(:log).returns(@logger)
    @test_start_time = Time.now
  end

  def test_add_task
    @x = false
    @worker_loop.run(0) do
      @worker_loop.stop
      @x = true
    end
    assert @x
  end

  def test_density
    # This shows how the tasks stay aligned with the period and don't drift.
    count = 0
    start = Time.now
    @worker_loop.run(0.01) do
      count +=1
      if count == 3
        @worker_loop.stop
        next
      end
    end
    elapsed = Time.now - start
    assert_in_delta 0.03, elapsed, 0.02
  end
  def test_task_error__standard
    @logger.expects(:debug)
    @logger.expects(:error)
    # This loop task will run twice
    done = false
    @worker_loop.run(0) do
      @worker_loop.stop
      done = true
      raise "Standard Error Test"
    end
    assert done
  end
  class BadBoy < Exception; end

  def test_task_error__exception
    @logger.expects(:error).once
    @logger.expects(:debug).once
    @worker_loop.run(0) do
      @worker_loop.stop
      raise BadBoy, "oops"
    end
  end
  def test_task_error__server
    @logger.expects(:error).never
    @logger.expects(:debug).once
    @worker_loop.run(0) do
      @worker_loop.stop
      raise NewRelic::Agent::ServerError, "Runtime Error Test"
    end
  end
end

Version data entries

29 entries across 29 versions & 3 rubygems

Version Path
dolores_rpm-3.2.0.6 test/new_relic/agent/worker_loop_test.rb
dolores_rpm-3.2.0.5 test/new_relic/agent/worker_loop_test.rb
dolores_rpm-3.2.0.4 test/new_relic/agent/worker_loop_test.rb
dolores_rpm-3.2.0.3 test/new_relic/agent/worker_loop_test.rb
dolores_rpm-3.2.0.2 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.3.2.beta1 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.3.1 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.3.1.beta2 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.3.1.beta1 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.3.0 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.3.0.beta1 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.2.0.1 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.2.0 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.2.0.beta2 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.2.0.beta1 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.1.2 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.1.2.beta2 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.1.2.beta1 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.1.1 test/new_relic/agent/worker_loop_test.rb
newrelic_rpm-3.1.1.beta3 test/new_relic/agent/worker_loop_test.rb