computron 0.1.0 → 0.2.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/README.rdoc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Computron is like ab on steroids, implemented in Ruby using em-http-request. It was designed out of a need to simulate real users on a website. It also does a few smart things like decode JSON into a Ruby hash so you can use those responses in your next requests.
4
4
 
5
- = The DSL
5
+ = The Simulation
6
6
 
7
7
  Computron is a simple DLS around HTTP em that makes more sense to write user tests.
8
8
 
data/Rakefile CHANGED
@@ -15,7 +15,6 @@ begin
15
15
  gem.add_dependency "colored", ">= 1.1"
16
16
  gem.add_development_dependency "rspec", ">= 1.2.9"
17
17
  gem.add_development_dependency "yard", ">= 0"
18
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
18
  end
20
19
  Jeweler::GemcutterTasks.new
21
20
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/bin/computron CHANGED
@@ -1,15 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- computron_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ computron_dir = File.join(File.dirname(__FILE__), '..', 'lib')
4
4
  $LOAD_PATH.unshift(computron_dir) unless $LOAD_PATH.include?(computron_dir)
5
5
 
6
- require 'rubygems'
7
- require 'computron'
6
+ $stdout.sync = true
8
7
 
9
- simulation = Computron::DSL.new(File.read(ARGV.last))
8
+ require 'computron'
10
9
 
11
10
  Signal.trap('INT'){
12
11
  EM.stop
13
12
  }
14
13
 
15
- simulation.run!
14
+ file = File.open(ARGV.last)
15
+
16
+ simulation = Computron::Simulation.new do
17
+ eval(file.read, binding, file.path)
18
+ end.run!
data/computron.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{computron}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brad Gessler"]
12
- s.date = %q{2010-05-24}
12
+ s.date = %q{2010-05-25}
13
13
  s.default_executable = %q{computron}
14
14
  s.description = %q{Computron was created to help Poll Everywhere peform load tests that simulate how real users work.}
15
15
  s.email = %q{brad@bradgessler.com}
@@ -31,12 +31,11 @@ Gem::Specification.new do |s|
31
31
  "computron.gemspec",
32
32
  "lib/computron.rb",
33
33
  "lib/computron/client.rb",
34
- "lib/computron/dsl.rb",
35
34
  "lib/computron/report.rb",
35
+ "lib/computron/simulation.rb",
36
36
  "spec/computron_spec.rb",
37
37
  "spec/spec.opts",
38
- "spec/spec_helper.rb",
39
- "test.rb"
38
+ "spec/spec_helper.rb"
40
39
  ]
41
40
  s.homepage = %q{http://github.com/bradgessler/computron}
42
41
  s.rdoc_options = ["--charset=UTF-8"]
@@ -161,7 +161,7 @@ module Computron
161
161
  end
162
162
  logger.info "#{status.ljust(3)} #{http.method.ljust(4)} #{http.uri}#{" (#{extra})".magenta if extra}\n #{http.response}\n"
163
163
  end
164
-
164
+
165
165
  # Simplifies em-http-client into something more suitable for tests. Interpets JSON, etc.
166
166
  def request(http_meth, url, opts={}, &block)
167
167
  response = Response.new
@@ -174,7 +174,7 @@ module Computron
174
174
  log_request(http)
175
175
  }
176
176
  request.errback {|http|
177
- log_request(http, "Network error or timeout.")
177
+ log_request(http, "Network error.")
178
178
  }
179
179
  end
180
180
 
@@ -1,11 +1,10 @@
1
1
  module Computron
2
- class DSL
3
-
2
+ class Simulation
4
3
  attr_reader :client
5
4
 
6
- def initialize(code=nil, &block)
5
+ def initialize(&block)
7
6
  @client = Client.new
8
- @simulation = Proc.new { code ? eval(code, self.send(:binding)) : instance_eval(&block) }
7
+ @simulation = Proc.new { instance_eval(&block) }
9
8
  end
10
9
 
11
10
  def run!
@@ -20,9 +19,9 @@ module Computron
20
19
  host ? @default_host = host : @default_host
21
20
  end
22
21
 
23
- def every(seconds, opts={}, &block)
22
+ def every(interval, opts={}, &block)
24
23
  timer = EventMachine::PeriodicTimer.new(0) do
25
- timer.interval = seconds
24
+ timer.interval = interval.respond_to?(:call) ? interval.call : interval
26
25
  block.call(timer)
27
26
  end
28
27
  end
@@ -42,6 +41,5 @@ module Computron
42
41
  url.concat path =~ /^\// ? path : "/#{path}" # Deal with leading /\
43
42
  url
44
43
  end
45
-
46
44
  end
47
45
  end
data/lib/computron.rb CHANGED
@@ -1,5 +1,8 @@
1
- $stdout.sync = true
1
+ dir = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
2
3
 
3
- require 'computron/client'
4
- require 'computron/dsl'
5
- require 'computron/report'
4
+ module Computron
5
+ autoload :Client, 'computron/client'
6
+ autoload :Simulation, 'computron/simulation'
7
+ autoload :Report, 'computron/report'
8
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Brad Gessler
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-24 00:00:00 -07:00
17
+ date: 2010-05-25 00:00:00 -07:00
18
18
  default_executable: computron
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -106,12 +106,11 @@ files:
106
106
  - computron.gemspec
107
107
  - lib/computron.rb
108
108
  - lib/computron/client.rb
109
- - lib/computron/dsl.rb
110
109
  - lib/computron/report.rb
110
+ - lib/computron/simulation.rb
111
111
  - spec/computron_spec.rb
112
112
  - spec/spec.opts
113
113
  - spec/spec_helper.rb
114
- - test.rb
115
114
  has_rdoc: true
116
115
  homepage: http://github.com/bradgessler/computron
117
116
  licenses: []
data/test.rb DELETED
@@ -1,34 +0,0 @@
1
- require '/Users/bgessler/Projects/imprezo/web/config/environment.rb'
2
- require 'lib/computron'
3
-
4
- clients_count = 2
5
- post_interval = 10
6
-
7
- clients = clients_count.times.map{ Computron::Client.new }
8
-
9
- default_host 'localhost:3000'
10
-
11
- get url('/events/1.json') do |response|
12
- response.ok {|json|
13
- event_id = json['event']['id']
14
- ticks_url = url("/events/#{event_id}/ticks/stream.json")
15
-
16
- clients.each do |client|
17
- client.long_poll ticks_url do |response, repoll|
18
- response.ok {|ticks|
19
- if last_tick = ticks.last
20
- repoll.url = "#{ticks_url}?since_id=#{last_tick['routing']['id']}"
21
- end
22
- }
23
- end
24
-
25
- every post_interval do
26
- client.post url("/events/#{event_id}/comments"), :body => Comment.new(:response => 'Hey!').to_json, :head => {'Content-Type' => 'application/json'} do |response|
27
- # response.ok { p "Super fun" }
28
- # response.found { p "Redirected" }
29
- # response.code(405) { p "Method not supported jagoff" }
30
- end
31
- end
32
- end
33
- }
34
- end