Merge "Add retry for dict file existence tests."

This commit is contained in:
Keisuke Kuroyanagi 2014-08-15 08:57:50 +00:00 committed by Android (Google) Code Review
commit 90d51d94b5

View file

@ -74,6 +74,23 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
} }
} }
private void checkExistenceAndRemoveDictFile(final Locale locale, final File dictFile) {
Log.d(TAG, "waiting for writing ...");
waitForWriting(locale);
if (!dictFile.exists()) {
try {
Log.d(TAG, dictFile + " is not existing. Wait "
+ WAIT_FOR_WRITING_FILE_IN_MILLISECONDS + " ms for writing.");
printAllFiles(dictFile.getParentFile());
Thread.sleep(WAIT_FOR_WRITING_FILE_IN_MILLISECONDS);
} catch (final InterruptedException e) {
Log.e(TAG, "Interrupted during waiting for writing the dict file.");
}
}
assertTrue("check exisiting of " + dictFile, dictFile.exists());
FileUtils.deleteRecursively(dictFile);
}
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
@ -210,10 +227,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
addAndWriteRandomWords(dummyLocale, numberOfWords, random, addAndWriteRandomWords(dummyLocale, numberOfWords, random,
true /* checksContents */); true /* checksContents */);
} finally { } finally {
Log.d(TAG, "waiting for writing ..."); checkExistenceAndRemoveDictFile(dummyLocale, dictFile);
waitForWriting(dummyLocale);
assertTrue("check exisiting of " + dictFile, dictFile.exists());
FileUtils.deleteRecursively(dictFile);
} }
} }
@ -251,20 +265,15 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
Log.d(TAG, "testStressTestForSwitchingLanguageAndAddingWords took " Log.d(TAG, "testStressTestForSwitchingLanguageAndAddingWords took "
+ (end - start) + " ms"); + (end - start) + " ms");
} finally { } finally {
Log.d(TAG, "waiting for writing ...");
for (int i = 0; i < numberOfLanguages; i++) { for (int i = 0; i < numberOfLanguages; i++) {
waitForWriting(dummyLocales[i]); checkExistenceAndRemoveDictFile(dummyLocales[i], dictFiles[i]);
}
for (final File dictFile : dictFiles) {
assertTrue("check exisiting of " + dictFile, dictFile.exists());
FileUtils.deleteRecursively(dictFile);
} }
} }
} }
public void testAddManyWords() { public void testAddManyWords() {
final Locale dummyLocale = final Locale dummyLocale =
new Locale(TEST_LOCALE_PREFIX + "random_words" + System.currentTimeMillis()); new Locale(TEST_LOCALE_PREFIX + "many_random_words" + System.currentTimeMillis());
final String dictName = ExpandableBinaryDictionary.getDictName( final String dictName = ExpandableBinaryDictionary.getDictName(
UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */); UserHistoryDictionary.NAME, dummyLocale, null /* dictFile */);
final File dictFile = ExpandableBinaryDictionary.getDictFile( final File dictFile = ExpandableBinaryDictionary.getDictFile(
@ -275,20 +284,7 @@ public class UserHistoryDictionaryTests extends AndroidTestCase {
try { try {
addAndWriteRandomWords(dummyLocale, numberOfWords, random, true /* checksContents */); addAndWriteRandomWords(dummyLocale, numberOfWords, random, true /* checksContents */);
} finally { } finally {
Log.d(TAG, "waiting for writing ..."); checkExistenceAndRemoveDictFile(dummyLocale, dictFile);
waitForWriting(dummyLocale);
if (!dictFile.exists()) {
try {
Log.d(TAG, dictFile +" is not existing. Wait "
+ WAIT_FOR_WRITING_FILE_IN_MILLISECONDS + " ms for writing.");
printAllFiles(dictFile.getParentFile());
Thread.sleep(WAIT_FOR_WRITING_FILE_IN_MILLISECONDS);
} catch (final InterruptedException e) {
Log.e(TAG, "Interrupted during waiting for writing the dict file.");
}
}
assertTrue("check exisiting of " + dictFile, dictFile.exists());
FileUtils.deleteRecursively(dictFile);
} }
} }