[chromium-dev] Re: seeking advice on writing a unittest in test_shell_tests that needs to use an IO thread

2009-09-24 Thread Darin Fisher
On Thu, Sep 24, 2009 at 9:57 PM, Adam Barth  wrote:

>
> On Thu, Sep 24, 2009 at 9:46 PM, Jenn Braithwaite (胡慧鋒)
>  wrote:
> > Answering my own question:
> > * Don't use ScopedRunnableMethodFactory to create a task to be run on a
> > different thread.
>
> Yeah, that doesn't work.  If you can think of more DCHECKs we can add
> to help you figure that out more quickly, send me a code review.  :)
>
> Adam


Actually, if we just port ScopedRunnableMethodFactory over to
WeakPtrFactory, we'll get those additional DCHECKs for free.  I was planning
on doing this once I have some free cycles, but if someone wants to beat me
to it, no prob :-)

-Darin

--~--~-~--~~~---~--~~
Chromium Developers mailing list: chromium-dev@googlegroups.com 
View archives, change email options, or unsubscribe: 
http://groups.google.com/group/chromium-dev
-~--~~~~--~~--~--~---



[chromium-dev] Re: seeking advice on writing a unittest in test_shell_tests that needs to use an IO thread

2009-09-24 Thread Adam Barth

On Thu, Sep 24, 2009 at 9:46 PM, Jenn Braithwaite (胡慧鋒)
 wrote:
> Answering my own question:
> * Don't use ScopedRunnableMethodFactory to create a task to be run on a
> different thread.

Yeah, that doesn't work.  If you can think of more DCHECKs we can add
to help you figure that out more quickly, send me a code review.  :)

Adam

--~--~-~--~~~---~--~~
Chromium Developers mailing list: chromium-dev@googlegroups.com 
View archives, change email options, or unsubscribe: 
http://groups.google.com/group/chromium-dev
-~--~~~~--~~--~--~---



[chromium-dev] Re: seeking advice on writing a unittest in test_shell_tests that needs to use an IO thread

2009-09-24 Thread 胡慧鋒
Answering my own question:
* Don't use ScopedRunnableMethodFactory to create a task to be run on a
different thread.  Either create a subclass of RefCountedThreadSafe or Task
to PostTask() to a different thread.  Do not make the test class a subclass
of RefCountedThreadSafe as the GTest code will not treat your test class as
a refcounted class.

* Access violation was my own (lame) bug.

Jenn

On Thu, Sep 24, 2009 at 11:38 AM, Jenn Braithwaite (胡慧鋒)
wrote:

> Hi,
> I'm writing some unittests in test_shell_tests.   Some of the tests need to
> run on the IO thread, but test_shell_tests uses the UI thread for its tests.
>
> Can anyone point me to some sample code (preferably a test_shell_test) that
> uses an IO thread in the test?
>
> So far, what I've tried is failing DCHECKS and throwing exceptions.
>
> TEST_F(MyTest, OneCase) {
>   base::WaitableEvent event(false, false);
>   base::Thread io_thread("My test thread");
>   base::Thread::Options options(MessageLoop::TYPE_IO, 0);
>   io_thread.StartWithOptions(options);
>   io_thread.message_loop()->PostTask(FROM_HERE,
>   method_factory_.NewRunnableMethod(&MyTest::OneCaseOnIO, &event));
>
>   // Wait until task is done before exiting the test.
>   event.Wait();
>
>   // :-(  fails NonThreadSafe::CalledOnValidThread() when task is deleted
>   // :-( access violation (on IO thread after this exits)
> }
>
> Appreciate any pointers on how to do this correctly.
>
> Thanks,
> Jenn
>

--~--~-~--~~~---~--~~
Chromium Developers mailing list: chromium-dev@googlegroups.com 
View archives, change email options, or unsubscribe: 
http://groups.google.com/group/chromium-dev
-~--~~~~--~~--~--~---