Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Problem testing certain Thread methods with Test::Unit

Reply
Thread Tools

Problem testing certain Thread methods with Test::Unit

 
 
Daniel Berger
Guest
Posts: n/a
 
      12-07-2007
Hi all,

Ruby 1.8.6

I'm trying to do write some basic tests for Thread#raise.
Unfortunately, because of the way Test::Unit implements assert_raise
(I think) I can't actually verify that Thread#raise actually works.
For example:

# Assume @thread created in setup
assert_raise(FooError){ @thread.raise(FooError) }

The above test won't work - no error is raised. Any suggestions on how
I should approach this?

Also, if anyone has any idea how to test that threads abort properly
with Thread.abort_on_exception = true, I'm all ears.

Thanks,

Dan


 
Reply With Quote
 
 
 
 
MenTaLguY
Guest
Posts: n/a
 
      12-07-2007
On Sat, 8 Dec 2007 02:33:59 +0900, Daniel Berger <(E-Mail Removed)> wrote:
> # Assume @thread created in setup
> assert_raise(FooError){ @thread.raise(FooError) }
>
> The above test won't work - no error is raised. Any suggestions on how
> I should approach this?


This should be reasonably robust:

t = Thread.new { sleep }
Thread.pass until t.status == "sleep"
t.raise FooError
assert_raise(FooError) { t.join }

> Also, if anyone has any idea how to test that threads abort properly
> with Thread.abort_on_exception = true, I'm all ears.


I don't think that's possible without starting a child Ruby process.

-mental


 
Reply With Quote
 
 
 
 
Daniel Berger
Guest
Posts: n/a
 
      12-07-2007
On Dec 7, 12:34 pm, MenTaLguY <(E-Mail Removed)> wrote:
> On Sat, 8 Dec 2007 02:33:59 +0900, Daniel Berger <(E-Mail Removed)> wrote:
> > # Assume @thread created in setup
> > assert_raise(FooError){ @thread.raise(FooError) }

>
> > The above test won't work - no error is raised. Any suggestions on how
> > I should approach this?

>
> This should be reasonably robust:
>
> t = Thread.new { sleep }
> Thread.pass until t.status == "sleep"
> t.raise FooError
> assert_raise(FooError) { t.join }


That works nicely, thank you.

> > Also, if anyone has any idea how to test that threads abort properly
> > with Thread.abort_on_exception = true, I'm all ears.

>
> I don't think that's possible without starting a child Ruby process.


If that's what it takes, that's what I'll do. Suggestions?

Thanks,

Dan

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Vista cannot obtain an IP address from certain routers or from certain non-Microsoft DHCP Brian W Wireless Networking 7 01-31-2010 03:46 AM
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Binding certain rows to certain columns in GridView? bernard.oflynn@gmail.com ASP .Net 2 03-25-2008 03:49 PM
Finding one certain line in a file is easy but how to look forheadlines and something just under this certain headline? kazaam Ruby 3 08-26-2007 03:34 PM
Expanding certain path to certain node in a JTree arun.hallan@gmail.com Java 0 01-08-2005 08:26 PM



Advertisments