I need to test a functionality of an application before to go in
production environment, unfortunately it isn't a ruby application, I
thought to use a script that will call a url 5 times simultaneously or
at least systematically, let's say every 10 seconds, is it possible with
ruby? Maybe using watir (but I don't think it can do simultaneus call)?
Any hint?
Watir can support multiple, concurrent calls. Create separate Watir::IE.new
in each thread.
Bret
···
On Thu, Jul 24, 2008 at 3:09 PM, Toki Toki <toki84@gmail.com> wrote:
Hi to all!
I need to test a functionality of an application before to go in
production environment, unfortunately it isn't a ruby application, I
thought to use a script that will call a url 5 times simultaneously or
at least systematically, let's say every 10 seconds, is it possible with
ruby? Maybe using watir (but I don't think it can do simultaneus call)?
Any hint?
I need to test a functionality of an application before to go in
production environment, unfortunately it isn't a ruby application, I
thought to use a script that will call a url 5 times simultaneously or
at least systematically, let's say every 10 seconds, is it possible with
ruby? Maybe using watir (but I don't think it can do simultaneus call)?
Any hint?
Yes. You could spawn threads and call the url from those.
%w[uri net/http].each{|l|require l}
10.times do
Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google.com/'\))}
end
Thanks for the answer.
It's not clear the first line of your code, could you explain it?
It's not clear the first line of your code, could you explain it?
%w[uri net/http].each{|l|require l}
%w[aaa bbb ccc] is an Array:
> %w[aaa bbb ccc]
["aaa", "bbb", "ccc"]
so it's a "each" method of an Array so:
require "uri"
require "net/http"
Well, I think is too much freak XD
Ok, so this:
%w[uri net/http].each{|l|require l}
10.times do
Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google.com/'\))}
end
is equal to this:
require 'net/http'
require 'uri'
10.times do
Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google.com/'\))}
end
Good, I've never used require with array.
But if I run the code above I get an error: url_call.rb:4: odd number
list for Hash
I think it's because of the curly braces that are viewed like an hash,
right? I don't know how Thread works in Ruby, but it seems that the
statements in the curly braces need to be on the same line as Thread.new
otherwise it give the error above...
···
El Jueves, 24 de Julio de 2008, Toki Toki escribió:
require 'net/http'
require 'uri'
10.times do
Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google.com/'\))}
end
Yes.
Good, I've never used require with array.
But if I run the code above I get an error: url_call.rb:4: odd number
list for Hash
I think it's because of the curly braces that are viewed like an hash,
right? I don't know how Thread works in Ruby, but it seems that the
statements in the curly braces need to be on the same line as Thread.new
otherwise it give the error above...
Thread.new gets a block, so you could as well write the code above as:
require 'net/http'
require 'uri'
10.times do
Thread.new do
Net::HTTP.get_response(URI.parse('http://www.google.com/'\))
end
end
maybe this is a bit more clear to you?
Thanks, I saw that the first curly brace need to be on the same line of
Thread.new.
I've tested the code above, but it seems that it doesn't work like I
thought because on the web server and application server logs I saw only
one request when I run the code (of course with the correct address),
maybe my statement isn't clear: I need to call a URL multiple time, like
if I press F5 on the browser...I've found a way using Watir example, but
without it would be better so I can use the script on any platform.
Thanks, I saw that the first curly brace need to be on the same line of
Thread.new.
I've tested the code above, but it seems that it doesn't work like I
thought because on the web server and application server logs I saw only
one request when I run the code (of course with the correct address),
maybe my statement isn't clear: I need to call a URL multiple time, like
if I press F5 on the browser...I've found a way using Watir example, but
without it would be better so I can use the script on any platform.
I've tested the code above, but it seems that it doesn't work like I
thought because on the web server and application server logs I saw only
one request when I run the code (of course with the correct address),
maybe my statement isn't clear: I need to call a URL multiple time, like
if I press F5 on the browser...I've found a way using Watir example, but
without it would be better so I can use the script on any platform.
It works if you run it from irb. If you call it from a script just call
Thread.join like Bret sad, or insert a sleep(10000) at the en of the
script.
Ok, this would work well?
require 'net/http'
require 'uri'
threads =
10.times do
threads << Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google.com/'\))}
end
threads.each {|x| x.join}
Or your original script with the sleep:
require 'net/http'
require 'uri'
10.times do
Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google.com/'\))}
end
sleep(10000)
It seems that I've some problem with the gem threadify or rubygems...I i
run the code that you've poste I get the error:
ruby threadify.rb
./threadify.rb:6: undefined method `threadify' for #<Array:0x38ce1c0>
(NoMethodError)
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
from threadify.rb:3
It seems that I've some problem with the gem threadify or rubygems...I i
run the code that you've poste I get the error:
ruby threadify.rb
./threadify.rb:6: undefined method `threadify' for #<Array:0x38ce1c0>
(NoMethodError)
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`gem_original_require'
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
from threadify.rb:3
You shouldn't give the test script the same name as the file you want
to require. Rename "threadify.rb" to something like
"threadify-test.rb" and it should work.
Regards,
Pit
···
2008/7/25 Toki Toki <toki84@gmail.com>:
It seems that I've some problem with the gem threadify or rubygems...I i
run the code that you've poste I get the error:
It seems that I've some problem with the gem threadify or rubygems...I i
run the code that you've poste I get the error:
ruby threadify.rb
...
You shouldn't give the test script the same name as the file you want
to require. Rename "threadify.rb" to something like
"threadify-test.rb" and it should work.
Regards,
Pit
Thanks, but I keep getting the same error even changing the name of the
script...I have this error only if I require an "external" gem...
--
Posted via http://www.ruby-forum.com/\.