speedos 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a05784e3dc6dad87f1ec5c55a6df8f2e93ca327
4
- data.tar.gz: 9aa76e9795b058283fd0e2ddcb2199180aefc25d
3
+ metadata.gz: 34abd33e531b6cff88c5fd2d4c377e86550d52a5
4
+ data.tar.gz: 85a162069d09232d2c2a744ef912704971584fc7
5
5
  SHA512:
6
- metadata.gz: 270c943ecf10c705e220265d966e461b310aceb5f10da8117c5552081a8d8ec0d35363c0d2d06b839bab00d1f598b11d3a91d8c3c600878d5ec0b8c1e8730b6a
7
- data.tar.gz: 217745696d7e639e51323f137ae49881b6b46ea85625e1b48f92c01925d3789891e783743f57f70c3e87d96f3db4d5d88c05b7b3819af4eca3156513bfc9dd32
6
+ metadata.gz: a24f7edce7176c3a2cb7a735512b6c71d01822cde282e1d434afbd92c5f631c883059c613b183525dd90977ad0a6c3fd7f78dad000f8bd4ab77ca9af17db34b6
7
+ data.tar.gz: 0b855b99e810e716936e29901a01201bf01bdadfc46038821cd29ccb1c36179201716c1d625e019561cd6b0a2a5a656db3cc3470aed7243d6e8cc6aed51552d6
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ gemspec
4
4
  gem 'rspec'
5
5
  gem 'database_cleaner'
6
6
  gem 'har', git: 'https://github.com/PeterWuMC/har.git'
7
+ gem 'selenium-webdriver', '2.35.1'
data/Gemfile.lock CHANGED
@@ -10,7 +10,7 @@ GIT
10
10
  PATH
11
11
  remote: .
12
12
  specs:
13
- speedos (0.0.10)
13
+ speedos (0.0.12)
14
14
  browsermob-proxy (= 0.1.3)
15
15
  capybara (= 2.1.0)
16
16
  faker (= 1.1.2)
@@ -80,7 +80,14 @@ GEM
80
80
  rspec-expectations (2.14.0)
81
81
  diff-lcs (>= 1.1.3, < 2.0)
82
82
  rspec-mocks (2.14.1)
83
+ rubyzip (0.9.9)
84
+ selenium-webdriver (2.35.1)
85
+ childprocess (>= 0.2.5)
86
+ multi_json (~> 1.0)
87
+ rubyzip (< 1.0.0)
88
+ websocket (~> 1.0.4)
83
89
  tzinfo (0.3.37)
90
+ websocket (1.0.7)
84
91
  xpath (2.0.0)
85
92
  nokogiri (~> 1.3)
86
93
 
@@ -91,4 +98,5 @@ DEPENDENCIES
91
98
  database_cleaner
92
99
  har!
93
100
  rspec
101
+ selenium-webdriver (= 2.35.1)
94
102
  speedos!
data/README.md CHANGED
@@ -4,10 +4,15 @@
4
4
  Speedos incorporates [BrowserMob Proxy](http://bmp.lightbody.net) along with [Capybara](https://github.com/jnicklas/capybara), recording the web traffic and time taken to load all elements on each of the pages within a user journey. The aim is to identify any performance related issues, such as specific items that take a long time to load on page.
5
5
 
6
6
  ## Installation
7
- Put speedos on your Gemfile and using the new HarView
7
+ Put speedos on your Gemfile
8
8
 
9
9
  gem 'speedos'
10
+
11
+ # MUST ADD: 'selenium-webdriver', '2.35.1'
10
12
  gem 'har', git: 'https://github.com/PeterWuMC/har.git'
13
+
14
+ # OPTIONAL (if you want to use a properly working harviewer):
15
+ gem 'selenium-webdriver', '2.35.1'
11
16
 
12
17
  Or, install it via rubygem
13
18
 
data/lib/speedos.rb CHANGED
@@ -11,4 +11,5 @@ require 'speedos/log'
11
11
  require 'speedos/configuration'
12
12
 
13
13
  require 'speedos/models/record'
14
+ require 'speedos/models/information'
14
15
  require 'speedos/models/entries'
@@ -7,15 +7,7 @@ module Speedos
7
7
  end
8
8
 
9
9
  def total_load_time
10
- earliest_start_time = nil
11
- latest_end_time = nil
12
- @raw.each do |e|
13
- start_time = Time.parse(e["startedDateTime"]).to_f * 1000
14
- end_time = start_time + e["time"]
15
- earliest_start_time = start_time if !earliest_start_time || earliest_start_time > start_time
16
- latest_end_time = end_time if !latest_end_time || latest_end_time < end_time
17
- end
18
- (latest_end_time && earliest_start_time) ? (latest_end_time - earliest_start_time) : 0
10
+ (latest_end_time && earliest_start_time) ? (latest_end_time - earliest_start_time) * 1000 : 0
19
11
  end
20
12
 
21
13
  def name
@@ -25,5 +17,29 @@ module Speedos
25
17
  def inspect
26
18
  "Entries: #{name}"
27
19
  end
20
+
21
+ def earliest_start_time
22
+ @earliest_start_time ||= begin
23
+ get_earliest_start_time_latest_end_time
24
+ earliest_start_time
25
+ end
26
+ end
27
+
28
+ def latest_end_time
29
+ @latest_end_time ||= begin
30
+ get_earliest_start_time_latest_end_time
31
+ latest_end_time
32
+ end
33
+ end
34
+
35
+ private
36
+ def get_earliest_start_time_latest_end_time
37
+ raw.each do |e|
38
+ start_time = Time.parse(e["startedDateTime"])
39
+ end_time = Time.at(start_time.to_f + (e["time"].to_f / 1000))
40
+ @earliest_start_time = start_time if !@earliest_start_time || @earliest_start_time > start_time
41
+ @latest_end_time = end_time if !@latest_end_time || @latest_end_time < end_time
42
+ end
43
+ end
28
44
  end
29
45
  end
@@ -0,0 +1,13 @@
1
+ module Speedos
2
+ class Information
3
+ include Mongoid::Document
4
+
5
+ embedded_in :record
6
+
7
+ field :page_name, type: String
8
+ field :began_at, type: Time
9
+ field :finished_at, type: Time
10
+ field :total_duration, type: Integer
11
+
12
+ end
13
+ end
@@ -3,6 +3,8 @@ module Speedos
3
3
  include Mongoid::Document
4
4
  include Mongoid::Timestamps
5
5
 
6
+ embeds_many :information
7
+
6
8
  field :success, type: Boolean
7
9
  field :log
8
10
 
@@ -24,12 +26,16 @@ module Speedos
24
26
  File.open(filename, 'w') { |f| f.write({log: self.log}.to_json)}
25
27
  end
26
28
 
27
- def self.report
28
- Record.successful.all.each do |record|
29
- puts record.id
30
- record.pages.each do |page|
31
- puts " %-30s %ss" % [page.all_names.first, (page.total_load_time / 1000).round(5)]
32
- end
29
+ def refresh_information
30
+ information = self.information
31
+ information.destroy_all
32
+ self.pages.each do |page|
33
+ information.create(
34
+ :page_name => page.name,
35
+ :began_at => page.earliest_start_time,
36
+ :finished_at => page.latest_end_time,
37
+ :total_duration => page.total_load_time
38
+ )
33
39
  end
34
40
  end
35
41
  end
@@ -14,9 +14,14 @@ module Speedos
14
14
  Log.error("#{e.backtrace}")
15
15
  success = false
16
16
  ensure
17
- Record.create(JSON.load(page.get_har.to_json).merge(success: success))
17
+ finialise_record(JSON.load(page.get_har.to_json)['log'], success)
18
18
  page.server_proxy.close
19
19
  page.server.stop
20
20
  end
21
+
22
+ def finialise_record(log, success)
23
+ record = Record.create(log: log, success: success)
24
+ record.refresh_information
25
+ end
21
26
  end
22
27
  end
@@ -1,31 +1,83 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Speedos::Entries do
4
- context '#total_load_time' do
5
- subject { Speedos::Entries }
4
+ describe '#get_earliest_start_time_latest_end_time' do
5
+ subject { Speedos::Entries.new(times) }
6
6
 
7
7
  context 'when all tasks start the same time' do
8
- it 'returns the greatest load time' do
9
- entries = subject.new([
10
- {'startedDateTime' => DateTime.new(2012,1,1,12).to_s, 'time' => 100},
11
- {'startedDateTime' => DateTime.new(2012,1,1,12).to_s, 'time' => 50},
12
- ])
13
- entries.total_load_time.should eq 100
8
+ let(:time) { Time.new(2012,1,1,12) }
9
+ let(:times) do
10
+ [
11
+ {'startedDateTime' => time.to_s, 'time' => 100},
12
+ {'startedDateTime' => time.to_s, 'time' => 50},
13
+ ]
14
+ end
15
+
16
+ before { subject.send(:total_load_time) }
17
+
18
+ it 'updates earliest_start_time' do
19
+ subject.earliest_start_time.should eq time
20
+ end
21
+
22
+ it 'updates the latest_end_time' do
23
+ end_time = Time.at(time.to_f + 100.0/1000)
24
+ subject.latest_end_time.to_f.should eq end_time.to_f
14
25
  end
15
26
  end
16
27
 
17
28
  context 'when tasks are started at the same time' do
18
- it 'returns the total time needed' do
19
- entries = subject.new([
20
- {'startedDateTime' => DateTime.new(2012,1,1,12,0,0).to_s, 'time' => 100},
21
- {'startedDateTime' => DateTime.new(2012,1,1,12,0,1).to_s, 'time' => 50},
22
- ])
23
- entries.total_load_time.should eq 1050
29
+ let(:earlier_time) { Time.new(2012,1,1,12,0,0) }
30
+ let(:later_time) { Time.new(2012,1,1,12,0,1) }
31
+ let(:times) do
32
+ [
33
+ {'startedDateTime' => earlier_time.to_s, 'time' => 100},
34
+ {'startedDateTime' => later_time.to_s, 'time' => 50},
35
+ ]
36
+ end
37
+
38
+ it 'updates the total time needed' do
39
+ subject.earliest_start_time.should eq earlier_time
40
+ end
41
+
42
+ it 'updates the latest_end_time' do
43
+ end_time = Time.at(later_time.to_f + 50.0/1000)
44
+ subject.latest_end_time.to_f.should eq end_time.to_f
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#total_load_time' do
50
+ subject { Speedos::Entries.new(double) }
51
+
52
+ let(:earliest_start_time) { Time.current }
53
+ let(:latest_end_time) { Time.current }
54
+
55
+ before do
56
+ subject.stub(:earliest_start_time).and_return(earliest_start_time)
57
+ subject.stub(:latest_end_time).and_return(latest_end_time)
58
+ end
59
+
60
+ context 'when either latest_end_time or earliest_start_time is empty' do
61
+ context 'when either latest_end_time is nil' do
62
+ let(:earliest_start_time) { nil }
63
+ its(:total_load_time) { should eq 0 }
24
64
  end
65
+
66
+ context 'when either earliest_start_time is nil' do
67
+ let(:earliest_start_time) { nil }
68
+ its(:total_load_time) { should eq 0 }
69
+ end
70
+ end
71
+
72
+ context 'when noth latest_end_time or earliest_start_time are not empty' do
73
+ let(:earliest_start_time) { Time.current }
74
+ let(:latest_end_time) { Time.current + 1.second }
75
+
76
+ its(:total_load_time) { should eq (latest_end_time - earliest_start_time) * 1000 }
25
77
  end
26
78
  end
27
79
 
28
- context '#name' do
80
+ describe '#name' do
29
81
  subject { Speedos::Entries.new([{'pageref' => 'page 1'}, {'pageref' => 'page 1'},]) }
30
82
 
31
83
  its(:name) { should eq 'page 1' }
@@ -41,7 +41,36 @@ describe Speedos::Record do
41
41
  subject.pages
42
42
  end
43
43
  end
44
+ end
45
+
46
+ describe '#refresh_information' do
47
+ subject { Speedos::Record.create }
48
+
49
+ let(:page) { double(name: 'name', earliest_start_time: Time.current, latest_end_time: Time.current, total_load_time: 0) }
50
+ let(:pages) { [page] }
51
+
52
+ before do
53
+ subject.stub(:pages).and_return(pages)
54
+ end
44
55
 
56
+ it 'populates pages information' do
57
+ subject.refresh_information
58
+ info = subject.information
59
+ info.size.should eq 1
60
+ info.first.page_name.should eq page.name
61
+ info.first.began_at.should eq page.earliest_start_time
62
+ info.first.finished_at.should eq page.latest_end_time
63
+ info.first.total_duration.should eq page.total_load_time
64
+ end
65
+
66
+ context 'when there is already information for the record' do
67
+ before { @info = subject.information.create }
68
+
69
+ it 'clears all existing records' do
70
+ subject.refresh_information
71
+ subject.information.should_not include @info
72
+ end
73
+ end
45
74
  end
46
75
 
47
76
  end
data/spec/spec_helper.rb CHANGED
@@ -27,8 +27,11 @@ RSpec.configure do |config|
27
27
 
28
28
  DatabaseCleaner[:mongoid].strategy = :truncation
29
29
 
30
- config.before :each do
31
- Mongoid.purge!
30
+ config.before(:each) do
31
+ DatabaseCleaner.start
32
+ end
33
+
34
+ config.after(:each) do
32
35
  DatabaseCleaner.clean
33
36
  end
34
37
  end
data/speedos.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.files = `git ls-files`.split($\)
9
9
  gem.name = 'speedos'
10
10
  gem.require_paths = ['lib']
11
- gem.version = "0.0.11"
11
+ gem.version = "0.0.12"
12
12
  gem.executables = 'speedos'
13
13
  gem.license = 'MIT'
14
14
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: speedos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - SimplyBusiness
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-03 00:00:00.000000000 Z
11
+ date: 2013-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -131,6 +131,7 @@ executables:
131
131
  extensions: []
132
132
  extra_rdoc_files: []
133
133
  files:
134
+ - .rspec
134
135
  - Gemfile
135
136
  - Gemfile.lock
136
137
  - LICENSE.txt
@@ -202,6 +203,7 @@ files:
202
203
  - lib/speedos/configuration.rb
203
204
  - lib/speedos/log.rb
204
205
  - lib/speedos/models/entries.rb
206
+ - lib/speedos/models/information.rb
205
207
  - lib/speedos/models/record.rb
206
208
  - lib/speedos/page.rb
207
209
  - lib/speedos/performance.rb