Skip to content

Commit

Permalink
add a runner for running tramples
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgolick committed Apr 30, 2009
1 parent 88b6d26 commit f77dcd8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/trample.rb
Expand Up @@ -4,6 +4,7 @@ module Trample
autoload :Configuration, File.dirname(__FILE__) + "/trample/configuration"
autoload :Page, File.dirname(__FILE__) + "/trample/page"
autoload :Session, File.dirname(__FILE__) + "/trample/session"
autoload :Runner, File.dirname(__FILE__) + "/trample/runner"

class << self
attr_reader :current_configuration
Expand Down
19 changes: 19 additions & 0 deletions lib/trample/runner.rb
@@ -0,0 +1,19 @@
module Trample
class Runner
attr_reader :config, :threads

def initialize(config)
@config = config
@threads = []
end

def trample
@config.concurrency.times do
threads << Thread.new(@config) do |c|
Session.new(c).trample
end
end
end
end
end

25 changes: 25 additions & 0 deletions test/runner_test.rb
@@ -0,0 +1,25 @@
require 'test_helper'

class RunnerTest < Test::Unit::TestCase
def setup
@config = Trample::Configuration.new { |t| t.concurrency 2 }
end

context "Running a trample" do
setup do
@runner = Trample::Runner.new(@config)
@runner.trample
end

before_should "spawn <concurrency> threads" do
mock.proxy(Thread).new(@config).times(2)
end

before_should "start <concurrency> sessions trampling" do
stub.proxy(Trample::Session).new(@config).times(2) do |s|
mock(s).trample
s
end
end
end
end

0 comments on commit f77dcd8

Please sign in to comment.