fiveruns-dash-ruby 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/scm_test.rb ADDED
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) << "/test_helper"
2
+ require 'date'
3
+
4
+ #weird problems with flexmock resulted in this
5
+ module Fiveruns
6
+ module Dash
7
+ class SvnSCM
8
+ private
9
+ def svn_info
10
+ <<-EOF
11
+ Path: .
12
+ URL: http://me.svnrepository.com/svn/dash/trunk
13
+ Repository Root: http://me.svnrepository.com/svn/dash/trunk
14
+ Repository UUID: f206d12c-05cc-4c44-99a1-426015a0eef1
15
+ Revision: 123
16
+ Node Kind: directory
17
+ Schedule: normal
18
+ Last Changed Author: acf
19
+ Last Changed Rev: 123
20
+ Last Changed Date: 2008-07-27 18:44:52 +0100 (Sun, 27 Jul 2008)
21
+ EOF
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ class ScmTest < Test::Unit::TestCase
28
+
29
+ include Fiveruns::Dash
30
+
31
+ context "All SCMs" do
32
+ should "find .git in gems/fiveruns_dash on locate_upwards" do
33
+ assert_match File.expand_path(File.join(File.dirname(__FILE__), '..')),
34
+ SCM.send(:locate_upwards, File.dirname(__FILE__), ".git" )
35
+ end
36
+
37
+ should "return nil from locate_upwards when no .git" do
38
+ assert_nil SCM.send(:locate_upwards, '/tmp', ".git" )
39
+ end
40
+
41
+ should "return nil from locate_upwards when root on posix" do
42
+ assert_nil SCM.send(:locate_upwards, "/", ".git" )
43
+ end
44
+
45
+ should "select the longest path when two available" do
46
+ assert_equal( "/Users/acf/foo/bar/baz" , SCM.send(:best_match, ["/Users/acf/foo/bar/baz", "/Users/acf/foo/bar/baz", "/Users/acf"]) )
47
+ end
48
+
49
+ end
50
+
51
+
52
+ context "Subversion SCM" do
53
+ setup do
54
+ @scm = SvnSCM.new( File.dirname(__FILE__) )
55
+ end
56
+
57
+ should "extract revision properly from svn info" do
58
+ assert_equal 123, @scm.revision
59
+ end
60
+
61
+ should "extract time properly from svn info" do
62
+ assert_equal DateTime.parse("2008-07-27 18:44:52 +0100"), @scm.time
63
+ end
64
+
65
+ should "extract URL properly from svn info" do
66
+ assert_equal "http://me.svnrepository.com/svn/dash/trunk", @scm.url
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) << "/test_helper"
2
+
3
+ class SessionTest < Test::Unit::TestCase
4
+
5
+ attr_reader :session
6
+
7
+ context "Session" do
8
+
9
+ setup do
10
+ mock!
11
+ @session = Session.new(@configuration)
12
+ end
13
+
14
+ should "start reporter in background by default" do
15
+ session.start
16
+ assert session.reporter.started?
17
+ assert session.reporter.background?
18
+ end
19
+
20
+ should "optionally start reporter in foreground" do
21
+ session.start(false)
22
+ assert session.reporter.started?
23
+ assert session.reporter.foreground?
24
+ end
25
+
26
+ context "data" do
27
+ should "have right number of metrics" do
28
+ assert_equal @metrics.size, session.data.size
29
+ end
30
+ end
31
+
32
+ context "info" do
33
+ should "have metric_infos" do
34
+ assert_kind_of Array, session.info[:metric_infos]
35
+ assert_equal @metrics.size, session.info[:metric_infos].size
36
+ end
37
+ should "have recipes" do
38
+ assert_kind_of Array, session.info[:recipes]
39
+ session.info[:recipes].each do |recipe|
40
+ assert_kind_of String, recipe[:name]
41
+ assert_kind_of String, recipe[:url]
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,96 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+
4
+ begin
5
+ require 'shoulda'
6
+ require 'flexmock/test_unit'
7
+ require 'fake_web'
8
+ rescue
9
+ puts "Please install the Shoulda, FakeWeb and flexmock gems to run the Dash plugin tests."
10
+ end
11
+
12
+ $:.unshift(File.dirname(__FILE__) << '/../lib')
13
+ # Require library files
14
+ require 'fiveruns/dash'
15
+
16
+ class Test::Unit::TestCase
17
+
18
+ include Fiveruns::Dash
19
+
20
+ def mock!
21
+ no_recipe_loading!
22
+ mock_configuration!
23
+ create_session!
24
+ mock_reporter!
25
+ end
26
+
27
+ def create_session!
28
+ @session = Session.new(@configuration)
29
+ end
30
+
31
+ def mock_configuration!
32
+ # Mock Configuration
33
+ @metrics = []
34
+ @metric_class = Class.new(Metric) do
35
+ def self.metric_type
36
+ :test
37
+ end
38
+ def info_id
39
+ 1
40
+ end
41
+ end
42
+ 3.times do |i|
43
+ @metrics << @metric_class.new("Metric#{i}") { 1 }
44
+ end
45
+ @recipes = []
46
+ @recipes << Fiveruns::Dash::Recipe.new(:foo, :url => 'http://foo.com')
47
+ @recipes << Fiveruns::Dash::Recipe.new(:foo2, :url => 'http://foo2.com')
48
+ @metrics << @metric_class.new("NonCustomMetric") { 2 }
49
+ @configuration = flexmock(:configuration) do |mock|
50
+ mock.should_receive(:metrics).and_return(@metrics)
51
+ mock.should_receive(:recipes).and_return(@recipes)
52
+ end
53
+ end
54
+
55
+ def mock_reporter!
56
+ @restarted = false
57
+ flexmock(Reporter).new_instances do |mock|
58
+ mock.should_receive(:run).and_return do |restarted|
59
+ @restarted = restarted
60
+ end
61
+ end
62
+ end
63
+
64
+ def mock_streams!
65
+ @original_stdout = $stdout
66
+ $stdout = StringIO.new
67
+ @original_stderr = $stderr
68
+ $stderr = StringIO.new
69
+ @original_logdev = Fiveruns::Dash.logger.instance_eval { @logdev }
70
+ @logdev = Fiveruns::Dash.logger.instance_eval { @logdev = StringIO.new }
71
+ end
72
+
73
+ def no_recipe_loading!
74
+ # For now, we just stub it out so we don't muddy the list of recipes
75
+ # due to environmental factors
76
+ flexmock(Fiveruns::Dash).should_receive(:load_recipes)
77
+ end
78
+
79
+ def assert_wrote(*args)
80
+ stream = args.last.is_a?(StringIO) ? args.pop : @logdev
81
+ stream.rewind
82
+ content = stream.read.to_s.downcase
83
+ args.each do |word|
84
+ assert content.include?(word.downcase)
85
+ end
86
+ end
87
+
88
+ def restore_streams!
89
+ if @original_stdout && @original_stderr
90
+ $stdout = @original_stdout
91
+ $stderr = @original_stderr
92
+ Fiveruns::Dash.logger.instance_eval { @logdev = @original_logdev }
93
+ end
94
+ end
95
+
96
+ end
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) << "/test_helper"
2
+
3
+ class TracingTest < Test::Unit::TestCase
4
+
5
+ attr_reader :metric
6
+
7
+ def self.time_me(depth = 0)
8
+ time_me(depth + 1) if depth < 5
9
+ end
10
+
11
+ context "Tracing" do
12
+
13
+ setup do
14
+ Thread.current[:trace] = Fiveruns::Dash::Trace.new([:subject, 'Test'])
15
+ end
16
+
17
+ teardown do
18
+ # Hacked 'uninstrument' until it's built-in
19
+ ::Fiveruns::Dash::Instrument.handlers.each do |handler|
20
+ if TracingTest.methods.include?(%r!:time_me_with_instrument_#{handler.hash}!)
21
+ (class << TracingTest; self; end).class_eval <<-EOCE
22
+ remove_method :time_me_with_instrument_#{handler.hash}
23
+ alias_method :time_me, :time_me_without_instrument_#{handler.hash}
24
+ remove_method :time_me_without_instrument_#{handler.hash}
25
+ EOCE
26
+ end
27
+ end
28
+ ::Fiveruns::Dash::Instrument.handlers.clear
29
+ end
30
+
31
+ context "metrics" do
32
+ setup do
33
+ @metric = TimeMetric.new(:time_mes, :method => time_method)
34
+ flexmock(@metric).should_receive(:info_id).and_return(1)
35
+ end
36
+ should "create a call graph" do
37
+ invoke
38
+ assert_correct_graph trace.data
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ private
45
+
46
+ def assert_correct_graph(node, depth = 0)
47
+ assert_equal 1, node.children.size
48
+ assert_equal 1, node.metrics.size
49
+ if depth < 4
50
+ node.children.each do |child|
51
+ assert_correct_graph(child, depth + 1)
52
+ end
53
+ end
54
+ end
55
+
56
+ def trace
57
+ Thread.current[:trace]
58
+ end
59
+
60
+ def time_method
61
+ 'TracingTest.time_me'
62
+ end
63
+
64
+ def invoke(number = 1)
65
+ number.times { TracingTest.time_me }
66
+ end
67
+
68
+ end
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) << "/test_helper"
2
+
3
+ class UpdateTest < Test::Unit::TestCase
4
+
5
+ context "Update" do
6
+
7
+ setup do
8
+ @update = Update.new(DataPayload.new({}))
9
+ end
10
+
11
+ context "an instance" do
12
+
13
+ context "GUID" do
14
+ setup do
15
+ @mock_pid = 'THE-PID'
16
+ flexmock(Process).should_receive(:pid).and_return(@mock_pid)
17
+ end
18
+ should "include PID" do
19
+ @update.guid.include?(@mock_pid)
20
+ end
21
+ should "start with a a timestamp" do
22
+ @update.guid[/^\d{10,}/]
23
+ end
24
+ should "be cached per instance" do
25
+ assert_equal @update.guid, @update.guid
26
+ end
27
+ end
28
+
29
+ context "storing data" do
30
+ setup do
31
+ @urls = %w(file:///tmp http://yahoo.com https://secure.thing.com)
32
+ end
33
+ should "find correct method" do
34
+ assert_equal [:file, :http, :http], @urls.map { |url| @update.send(:storage_method_for, URI.parse(url).scheme) }
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+
42
+ end
data/version.yml ADDED
@@ -0,0 +1,3 @@
1
+ major: 0
2
+ minor: 7
3
+ patch: 0
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fiveruns-dash-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - FiveRuns Development Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-28 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: shoulda
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ description: Provides an API to send metrics to the FiveRuns Dash service
34
+ email: dev@fiveruns.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - README.rdoc
43
+ - Rakefile
44
+ - version.yml
45
+ - lib/fiveruns
46
+ - lib/fiveruns/dash
47
+ - lib/fiveruns/dash/configuration.rb
48
+ - lib/fiveruns/dash/exception_recorder.rb
49
+ - lib/fiveruns/dash/host.rb
50
+ - lib/fiveruns/dash/instrument.rb
51
+ - lib/fiveruns/dash/metric.rb
52
+ - lib/fiveruns/dash/recipe.rb
53
+ - lib/fiveruns/dash/reporter.rb
54
+ - lib/fiveruns/dash/scm.rb
55
+ - lib/fiveruns/dash/session.rb
56
+ - lib/fiveruns/dash/store
57
+ - lib/fiveruns/dash/store/file.rb
58
+ - lib/fiveruns/dash/store/http.rb
59
+ - lib/fiveruns/dash/threads.rb
60
+ - lib/fiveruns/dash/trace.rb
61
+ - lib/fiveruns/dash/typable.rb
62
+ - lib/fiveruns/dash/update.rb
63
+ - lib/fiveruns/dash/version.rb
64
+ - lib/fiveruns/dash.rb
65
+ - test/collector_communication_test.rb
66
+ - test/configuration_test.rb
67
+ - test/exception_recorder_test.rb
68
+ - test/file_store_test.rb
69
+ - test/fixtures
70
+ - test/fixtures/http_store_test
71
+ - test/fixtures/http_store_test/response.json
72
+ - test/http_store_test.rb
73
+ - test/metric_test.rb
74
+ - test/recipe_test.rb
75
+ - test/reliability_test.rb
76
+ - test/reporter_test.rb
77
+ - test/scm_test.rb
78
+ - test/session_test.rb
79
+ - test/test_helper.rb
80
+ - test/tracing_test.rb
81
+ - test/update_test.rb
82
+ - recipes/jruby.rb
83
+ - recipes/ruby.rb
84
+ has_rdoc: true
85
+ homepage: http://github.com/fiveruns/dash-ruby
86
+ post_install_message:
87
+ rdoc_options:
88
+ - --inline-source
89
+ - --charset=UTF-8
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ version:
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ version:
104
+ requirements: []
105
+
106
+ rubyforge_project: fiveruns
107
+ rubygems_version: 1.2.0
108
+ signing_key:
109
+ specification_version: 2
110
+ summary: FiveRuns Dash core library for Ruby
111
+ test_files: []
112
+