From 816a8a0fd85ca0327436f8bd1cfa6928600ebc5d Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 7 Feb 2012 19:22:37 +0900 Subject: [PATCH] Fix a race condition that makes tests unstable Change-Id: Ic19d380eb64855884bc6ded8547c200dd772ffe9 --- .../com/android/inputmethod/latin/LatinIME.java | 2 +- .../android/inputmethod/latin/InputLogicTests.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index e4339318b..5b7efaebb 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -186,7 +186,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private View mKeyPreviewBackingView; private View mSuggestionsContainer; private SuggestionsView mSuggestionsView; - private Suggest mSuggest; + /* package for tests */ Suggest mSuggest; private CompletionInfo[] mApplicationSpecifiedCompletions; private InputMethodManagerCompatWrapper mImm; diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index 693352c85..fef704a0e 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -111,6 +111,20 @@ public class InputLogicTests extends ServiceTestCase { mLatinIME.onStartInputView(ei, false); mLatinIME.onCreateInputMethodInterface().startInput(ic, ei); mInputConnection = ic; + // Wait for the main dictionary to be loaded (we need it for auto-correction tests) + int remainingAttempts = 10; + while (remainingAttempts > 0 && !mLatinIME.mSuggest.hasMainDictionary()) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + // Don't do much + } finally { + --remainingAttempts; + } + } + if (!mLatinIME.mSuggest.hasMainDictionary()) { + throw new RuntimeException("Can't initialize the main dictionary"); + } } // type(int) and type(String): helper methods to send a code point resp. a string to LatinIME.