File: thread_test.rb

package info (click to toggle)
ruby-samuel 0.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 172 kB
  • sloc: ruby: 735; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 841 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'test_helper'

class ThreadTest < Test::Unit::TestCase
  context "when logging multiple requests at once" do
    setup do
      @log = StringIO.new
      Samuel.logger = Logger.new(@log)
      FakeWeb.register_uri(:get, /example\.com/, :status => [200, "OK"])
      threads = []
      5.times do |i|
        threads << Thread.new(i) do |n|
          Samuel.with_config :label => "Example #{n}" do
            Thread.pass
            open "http://example.com/#{n}"
          end
        end
      end
      threads.each { |t| t.join }
      @log.rewind
    end

    should "not let configuration blocks interfere with eachother" do
      @log.each_line do |line|
        matches = %r|Example (\d+).*example\.com/(\d+)|.match(line)
        assert_not_nil matches
        assert_equal matches[1], matches[2]
      end
    end
  end
end