smokey 0.0.1 → 0.0.2
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/lib/scripts/base_script.rb +7 -0
- data/lib/scripts/homepage.rb +15 -0
- data/lib/smokey.rb +30 -3
- data/lib/smokey/logger.rb +21 -0
- data/lib/smokey/request.rb +22 -0
- data/lib/smokey/timer.rb +7 -0
- data/lib/smokey/version.rb +1 -1
- data/lib/smokey/virtual_user.rb +52 -0
- data/spec/smokey_spec.rb +15 -0
- metadata +9 -1
@@ -0,0 +1,15 @@
|
|
1
|
+
class Homepage < BaseScript
|
2
|
+
def initialize(base_url)
|
3
|
+
@base_url = base_url
|
4
|
+
@logger = Logger.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def run
|
8
|
+
timer = Timer.new.time do
|
9
|
+
request = Request.new("bla", "bla")
|
10
|
+
request.get("#{@base_url}/people")
|
11
|
+
end
|
12
|
+
@logger.log("info", "response time: #{timer.round(2)} seconds")
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/lib/smokey.rb
CHANGED
@@ -1,5 +1,32 @@
|
|
1
|
-
require "smokey/version"
|
2
|
-
|
3
1
|
module Smokey
|
4
|
-
|
2
|
+
Dir[File.dirname(__FILE__) + '/smokey/*.rb'].each {|file| require file }
|
3
|
+
Dir[File.dirname(__FILE__) + '/scripts/*.rb'].each {|file| require file }
|
4
|
+
|
5
|
+
class Runner
|
6
|
+
attr_reader :testscript, :vusers, :base_url, :duration, :delay, :rampup, :think_time
|
7
|
+
|
8
|
+
def initialize(testscript, vusers, base_url, duration, delay, rampup, think_time)
|
9
|
+
@testscript = testscript
|
10
|
+
@vusers = vusers
|
11
|
+
@base_url = base_url
|
12
|
+
@duration = duration
|
13
|
+
@delay = delay
|
14
|
+
@rampup = rampup
|
15
|
+
@think_time = think_time
|
16
|
+
end
|
17
|
+
|
18
|
+
def start_test
|
19
|
+
threads = []
|
20
|
+
@vusers.times do
|
21
|
+
thread = Thread.new do
|
22
|
+
VirtualUser.new(@testscript, @base_url).start
|
23
|
+
end
|
24
|
+
threads << thread
|
25
|
+
end
|
26
|
+
threads.each { |t| t.join }
|
27
|
+
end
|
28
|
+
end
|
5
29
|
end
|
30
|
+
|
31
|
+
@smokey = Smokey::Runner.new('Homepage', 5, 'http://localhost:3000', 10, 5, 1, 2)
|
32
|
+
@smokey.start_test
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "redis"
|
2
|
+
|
3
|
+
class Logger
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@redis = Redis.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def log(type, item)
|
10
|
+
case type
|
11
|
+
when "error"
|
12
|
+
puts "ERROR - #{item}"
|
13
|
+
when "success"
|
14
|
+
puts "SUCCESS - #{item}"
|
15
|
+
when "info"
|
16
|
+
@redis.set("logje", "INFO - #{item}")
|
17
|
+
storage = @redis.get("logje")
|
18
|
+
puts storage
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
class Request
|
4
|
+
def initialize(username, password)
|
5
|
+
@auth = { username: username, password: password }
|
6
|
+
@logger = Logger.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(url, options={})
|
10
|
+
begin
|
11
|
+
options.merge!({basic_auth: @auth})
|
12
|
+
response = HTTParty.get(url, options)
|
13
|
+
@logger.log("info", "#{response.code} - #{response.message}")
|
14
|
+
rescue => e
|
15
|
+
e.response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def post(url, parameters)
|
20
|
+
# RestClient.post(url, parameters)
|
21
|
+
end
|
22
|
+
end
|
data/lib/smokey/timer.rb
ADDED
data/lib/smokey/version.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
class VirtualUser
|
2
|
+
|
3
|
+
def initialize(testscript, base_url)
|
4
|
+
@testscript = testscript
|
5
|
+
@base_url = base_url
|
6
|
+
@logger = Logger.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def start
|
10
|
+
@logger.log("info", "Script started")
|
11
|
+
script = Kernel.const_get(@testscript)
|
12
|
+
script = script.new(@base_url)
|
13
|
+
script.run
|
14
|
+
@logger.log("info", "Script finished")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
=begin
|
19
|
+
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
20
|
+
require File.join(dir, 'httparty')
|
21
|
+
|
22
|
+
class TripIt
|
23
|
+
include HTTParty
|
24
|
+
base_uri 'http://www.tripit.com'
|
25
|
+
debug_output
|
26
|
+
|
27
|
+
def initialize(email, password)
|
28
|
+
@email = email
|
29
|
+
response = self.class.get('/account/login')
|
30
|
+
response = self.class.post(
|
31
|
+
'/account/login',
|
32
|
+
:body => {
|
33
|
+
:login_email_address => email,
|
34
|
+
:login_password => password
|
35
|
+
},
|
36
|
+
:headers => {'Cookie' => response.headers['Set-Cookie']}
|
37
|
+
)
|
38
|
+
@cookie = response.request.options[:headers]['Cookie']
|
39
|
+
end
|
40
|
+
|
41
|
+
def account_settings
|
42
|
+
self.class.get('/account/edit', :headers => {'Cookie' => @cookie})
|
43
|
+
end
|
44
|
+
|
45
|
+
def logged_in?
|
46
|
+
account_settings.include? "You're logged in as #{@email}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
tripit = TripIt.new('email', 'password')
|
51
|
+
puts "Logged in: #{tripit.logged_in?}"
|
52
|
+
=end
|
data/spec/smokey_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'smokey'
|
3
|
+
|
4
|
+
describe Smokey do
|
5
|
+
before :each do
|
6
|
+
@smokey = Smokey::Runner.new(5, 'http://localhost:3000', 10, 5, 1, 2)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "new" do
|
10
|
+
it "returns a Smokey object" do
|
11
|
+
@smokey.should be_an_instance_of Smokey::Runner
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smokey
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -39,9 +39,16 @@ files:
|
|
39
39
|
- LICENSE.txt
|
40
40
|
- README.md
|
41
41
|
- Rakefile
|
42
|
+
- lib/scripts/base_script.rb
|
43
|
+
- lib/scripts/homepage.rb
|
42
44
|
- lib/smokey.rb
|
45
|
+
- lib/smokey/logger.rb
|
46
|
+
- lib/smokey/request.rb
|
47
|
+
- lib/smokey/timer.rb
|
43
48
|
- lib/smokey/version.rb
|
49
|
+
- lib/smokey/virtual_user.rb
|
44
50
|
- smokey.gemspec
|
51
|
+
- spec/smokey_spec.rb
|
45
52
|
- spec/spec_helper.rb
|
46
53
|
homepage: ''
|
47
54
|
licenses: []
|
@@ -69,4 +76,5 @@ specification_version: 3
|
|
69
76
|
summary: With Smokey it is easy to execute a simple performance test for a webapp
|
70
77
|
to see if it can handle the load.
|
71
78
|
test_files:
|
79
|
+
- spec/smokey_spec.rb
|
72
80
|
- spec/spec_helper.rb
|