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
-~----------~----~----~----~------~----~------~--~---

Reply via email to