Пример #1
0
 /**
  * This is a hack.
  *
  * <p>Startup results in us writing prefs -- we fetch the Distribution, which caches its state.
  * Our tests try to wipe those prefs, but apparently sometimes race with startup, which leads to
  * us not getting one of our expected messages. The test fails.
  *
  * <p>This hack waits for any existing background tasks -- such as the one that writes prefs -- to
  * finish before we begin the test.
  */
 private void waitForBackgroundHappiness() {
   final Object signal = new Object();
   final Runnable done =
       new Runnable() {
         @Override
         public void run() {
           synchronized (signal) {
             signal.notify();
           }
         }
       };
   synchronized (signal) {
     ThreadUtils.postToBackgroundThread(done);
     try {
       signal.wait();
     } catch (InterruptedException e) {
       mAsserter.ok(false, "InterruptedException waiting on background thread.", e.toString());
     }
   }
   mAsserter.dumpLog("Background task completed. Proceeding.");
 }