Sha256: 50bdd0f5c9af4004ac11ed399c1da538a337145fc80029ea684caf6c67e67dc1

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require 'json'
require 'spec_helper'
require 'fluent/rubyprof'

describe Fluent::Rubyprof do
  CONFIG_PATH = File.join(File.dirname(__FILE__), 'fluent.conf')
  BIN_DIR = File.join(ROOT, 'bin')
  OUTPUT_FILE = File.join(File.dirname(__FILE__), 'test.txt')

  context '#parse_options' do
    it 'incorrect subcommand' do
      expect { Fluent::Rubyprof.new.parse_options(['foo']) }.to raise_error(OptionParser::InvalidOption)
    end

    it 'correct measure_mode' do
      expect { Fluent::Rubyprof.new.parse_options(['start', '-m', 'CPU_TIME']) }.not_to raise_error
    end

    it 'incorrect measure_mode' do
      expect { Fluent::Rubyprof.new.parse_options(['start', '-m', 'foo']) }.to raise_error(OptionParser::InvalidOption)
    end

    it 'correct printer' do
      expect { Fluent::Rubyprof.new.parse_options(['start', '-P', 'graph']) }.not_to raise_error
    end

    it 'incorrect printer' do
      expect { Fluent::Rubyprof.new.parse_options(['start', '-P', 'bar']) }.to raise_error(OptionParser::InvalidArgument)
    end
  end

  context 'profiling' do
    before :all do
      @fluentd_pid = spawn('fluentd', '-c', CONFIG_PATH, out: '/dev/null')
      sleep 2

      system("#{File.join(BIN_DIR, 'fluent-rubyprof')} start")
      sleep 2

      system("#{File.join(BIN_DIR, 'fluent-rubyprof')} stop -o #{OUTPUT_FILE}")
      sleep 1
    end

    after :all do
      Process.kill(:TERM, @fluentd_pid)
      Process.waitall
    end

    it 'should output' do
      expect(File.size?(OUTPUT_FILE)).to be_truthy
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-rubyprof-0.2.0 spec/fluent-rubyprof/rubyprof_spec.rb