[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Simultaneously URL call, is it possible?

Toki Toki

7/24/2008 8:10:00 PM

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?

Thanks.

Best regards.
--
Posted via http://www.ruby-....

21 Answers

Bret Pettichord

7/24/2008 8:53:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

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?
>
> Thanks.
>
> Best regards.
> --
> Posted via http://www.ruby-....
>
>


--
Bret Pettichord
CTO, WatirCraft LLC, http://www.wati...
Lead Developer, Watir, http://wtr.rub...
Blog (Essays), http://www.io.com/~...
MiniBlog (Links), http://feeds.feedburner.com/br...

matu

7/24/2008 8:54:00 PM

0

Toki Toki wrote:

> 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...))}
end

Toki Toki

7/24/2008 9:01:00 PM

0

matu wrote:
> Toki Toki wrote:
>
>> 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...))}
> end

Thanks for the answer.

It's not clear the first line of your code, could you explain it?

Thanks.
--
Posted via http://www.ruby-....

Toki Toki

7/24/2008 9:04:00 PM

0

Bret Pettichord wrote:
> Watir can support multiple, concurrent calls. Create separate
> Watir::IE.new
> in each thread.
>
> Bret

Thanks, I didn't know that watir support concurrent calls. If I create
multiple Watir::IE.new then they will use the same IE process?
--
Posted via http://www.ruby-....

Iñaki Baz Castillo

7/24/2008 9:07:00 PM

0

El Jueves, 24 de Julio de 2008, Toki Toki escribi=C3=B3:
> 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:

irb> %w[aaa bbb ccc]=20
["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


=2D-=20
I=C3=B1aki Baz Castillo

Bret Pettichord

7/24/2008 9:12:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Thu, Jul 24, 2008 at 4:04 PM, Toki Toki <toki84@gmail.com> wrote:

> Thanks, I didn't know that watir support concurrent calls. If I create
> multiple Watir::IE.new then they will use the same IE process?
>

Yes. But you can use Watir::IE.new_process instead and then each one will be
in a separate process.

Bret



--
Bret Pettichord
CTO, WatirCraft LLC, http://www.wati...
Lead Developer, Watir, http://wtr.rub...
Blog (Essays), http://www.io.com/~...
MiniBlog (Links), http://feeds.feedburner.com/br...

Toki Toki

7/24/2008 9:20:00 PM

0

Iñaki Baz Castillo wrote:
> El Jueves, 24 de Julio de 2008, Toki Toki escribió:
>> 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:
>
> irb> %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...))}
end

is equal to this:

require 'net/http'
require 'uri'
10.times do
Thread.new
{Net::HTTP.get_response(URI.parse('http://www.google...))}
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...
--
Posted via http://www.ruby-....

S2

7/25/2008 7:54:00 AM

0

Toki Toki wrote:
> 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...))}
> end
>
> is equal to this:
>
> require 'net/http'
> require 'uri'
> 10.times do
> Thread.new
> {Net::HTTP.get_response(URI.parse('http://www.google...))}
> 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...))
end
end

maybe this is a bit more clear to you?

Toki Toki

7/25/2008 6:25:00 PM

0

S2 wrote:
> Toki Toki wrote:
>> require 'net/http'
>> require 'uri'
>> 10.times do
>> Thread.new
>> {Net::HTTP.get_response(URI.parse('http://www.google...))}
>> 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...))
> 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.

Best regards.
--
Posted via http://www.ruby-....

Bret Pettichord

7/25/2008 7:02:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Fri, Jul 25, 2008 at 1:25 PM, Toki Toki <toki84@gmail.com> wrote:

> > require 'net/http'
> > require 'uri'
> > 10.times do
> > Thread.new do
> > Net::HTTP.get_response(URI.parse('http://www.google.com/'<http://www.google.c...
> ))
> > 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.
>
>
I think this needs a call to Thread#join after all the the threads have been
created. Otherwise the script will exit before the threads have executed.

Bret



--
Bret Pettichord
CTO, WatirCraft LLC, http://www.wati...
Lead Developer, Watir, http://wtr.rub...
Blog (Essays), http://www.io.com/~...
MiniBlog (Links), http://feeds.feedburner.com/br...