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
# 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
···
On Sat, 8 Dec 2007 02:33:59 +0900, Daniel Berger <djberg96@gmail.com> 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
···
On Dec 7, 12:34 pm, MenTaLguY <men...@rydia.net> wrote:
On Sat, 8 Dec 2007 02:33:59 +0900, Daniel Berger <djber...@gmail.com> wrote:
I'm not aware of a portable way to do that offhand, although there was
an RCR for that floating around a while back.
-mental
···
On Sat, 2007-12-08 at 07:21 +0900, Daniel Berger wrote:
> > 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?
Absent a more portable way, fork should work.
-mental
···
On Wed, 12 Dec 2007 12:18:43 +0900, MenTaLguY <mental@rydia.net> wrote:
On Sat, 2007-12-08 at 07:21 +0900, Daniel Berger wrote:
> > 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?
I'm not aware of a portable way to do that offhand, although there was
an RCR for that floating around a while back.