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 (胡慧鋒) <[email protected]>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: [email protected] View archives, change email options, or unsubscribe: http://groups.google.com/group/chromium-dev -~----------~----~----~----~------~----~------~--~---
