Fix flaky test

This CL fixes a focus test where we could be
checking callbacks w/o waiting for it to arrive.

Change-Id: I7b67ab69dc01d798e63488e2897e1e110233fa17
diff --git a/v7/recyclerview/tests/src/android/support/v7/widget/RecyclerViewLayoutTest.java b/v7/recyclerview/tests/src/android/support/v7/widget/RecyclerViewLayoutTest.java
index 366758a..61312d3 100644
--- a/v7/recyclerview/tests/src/android/support/v7/widget/RecyclerViewLayoutTest.java
+++ b/v7/recyclerview/tests/src/android/support/v7/widget/RecyclerViewLayoutTest.java
@@ -62,7 +62,7 @@
     private static final int FLAG_VERTICAL = 1 << 1;
     private static final int FLAG_FLING = 1 << 2;
 
-    private static final boolean DEBUG = true;
+    private static final boolean DEBUG = false;
 
     private static final String TAG = "RecyclerViewLayoutTest";
 
@@ -174,9 +174,9 @@
     }
 
     @Test
-    public void testFocusSearchFailFrozen() throws Throwable {
+    public void  testFocusSearchFailFrozen() throws Throwable {
         RecyclerView recyclerView = new RecyclerView(getActivity());
-
+        final CountDownLatch focusLatch = new CountDownLatch(1);
         final AtomicInteger focusSearchCalled = new AtomicInteger(0);
         TestLayoutManager tlm = new TestLayoutManager() {
             @Override
@@ -199,6 +199,7 @@
             public View onFocusSearchFailed(View focused, int direction, RecyclerView.Recycler recycler,
                     RecyclerView.State state) {
                 focusSearchCalled.addAndGet(1);
+                focusLatch.countDown();
                 return null;
             }
         };
@@ -222,9 +223,9 @@
         sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
         assertEquals("onFocusSearchFailed should not be called when layout is frozen",
                 0, focusSearchCalled.get());
-
         freezeLayout(false);
         sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
+        assertTrue(focusLatch.await(2, TimeUnit.SECONDS));
         assertEquals(1, focusSearchCalled.get());
     }