summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-16 07:05:23 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-16 07:05:23 +0000
commit7b7bbbe82533e74b60a924dc4d563f6d3f07482c (patch)
tree45c2c8f1abf86a9a86d0e92d57930de6a40b306d
parent9e743cddfd631038fe6f1cdde050e18d61319ec6 (diff)
downloadchromium_src-7b7bbbe82533e74b60a924dc4d563f6d3f07482c.zip
chromium_src-7b7bbbe82533e74b60a924dc4d563f6d3f07482c.tar.gz
chromium_src-7b7bbbe82533e74b60a924dc4d563f6d3f07482c.tar.bz2
Re-enable FileWatcher tests on mac, but mark them as flaky.
Review URL: http://codereview.chromium.org/1021002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41690 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/file_watcher_mac.cc2
-rw-r--r--chrome/browser/file_watcher_unittest.cc31
2 files changed, 24 insertions, 9 deletions
diff --git a/chrome/browser/file_watcher_mac.cc b/chrome/browser/file_watcher_mac.cc
index be572d5..638654c 100644
--- a/chrome/browser/file_watcher_mac.cc
+++ b/chrome/browser/file_watcher_mac.cc
@@ -38,6 +38,7 @@ class FileWatcherImpl : public FileWatcher::PlatformDelegate {
ChromeThread::PostTask(ChromeThread::UI, FROM_HERE,
NewRunnableMethod(this, &FileWatcherImpl::WatchImpl, path, delegate));
} else {
+ LOG(INFO) << "Adding FileWatcher watch.";
// During unittests, there is only one thread and it is both the UI
// thread and the file thread.
WatchImpl(path, delegate);
@@ -103,6 +104,7 @@ void FSEventsCallback(ConstFSEventStreamRef stream,
NewRunnableMethod(watcher, &FileWatcherImpl::OnFSEventsCallback,
FilePath(paths[i])));
} else {
+ LOG(INFO) << "FileWatcher event callback for " << paths[i];
// During unittests, there is only one thread and it is both the UI
// thread and the file thread.
watcher->OnFSEventsCallback(FilePath(paths[i]));
diff --git a/chrome/browser/file_watcher_unittest.cc b/chrome/browser/file_watcher_unittest.cc
index 0483aae..5db2138 100644
--- a/chrome/browser/file_watcher_unittest.cc
+++ b/chrome/browser/file_watcher_unittest.cc
@@ -17,11 +17,21 @@
#include "base/thread.h"
#include "testing/gtest/include/gtest/gtest.h"
+#if defined(OS_MACOSX)
+// TODO(tony): Tests are flaky on mac. http://crbug.com/38188
+#define MAYBE(name) FLAKY_ ## name
+#else
+#define MAYBE(name) name
+#endif
+
namespace {
// For tests where we wait a bit to verify nothing happened
const int kWaitForEventTime = 500;
+// Maximum amount of time to wait on a test.
+const int kMaxTestTimeMs = 10 * 1000;
+
class FileWatcherTest : public testing::Test {
public:
// Implementation of FileWatcher on Mac requires UI loop.
@@ -43,6 +53,10 @@ class FileWatcherTest : public testing::Test {
virtual void SetUp() {
temp_dir_.reset(new ScopedTempDir);
ASSERT_TRUE(temp_dir_->CreateUniqueTempDir());
+ // Make sure that not getting an event doesn't cause the whole
+ // test suite to hang.
+ loop_.PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask,
+ kMaxTestTimeMs);
}
FilePath test_file() {
@@ -51,6 +65,8 @@ class FileWatcherTest : public testing::Test {
// Write |content| to the test file. Returns true on success.
bool WriteTestFile(const std::string& content) {
+ // Logging to try and figure out why these tests are flaky on mac.
+ LOG(INFO) << "WriteTestFile";
int write_size = file_util::WriteFile(test_file(), content.c_str(),
content.length());
return write_size == static_cast<int>(content.length());
@@ -129,10 +145,8 @@ class TestDelegate : public FileWatcher::Delegate {
};
-#if !defined(OS_MACOSX)
-// TODO(tony): Test is flakey on mac. http://crbug.com/38188
// Basic test: Create the file and verify that we notice.
-TEST_F(FileWatcherTest, NewFile) {
+TEST_F(FileWatcherTest, MAYBE(NewFile)) {
FileWatcher watcher;
TestDelegate delegate(this);
ASSERT_TRUE(watcher.Watch(test_file(), &delegate));
@@ -143,7 +157,7 @@ TEST_F(FileWatcherTest, NewFile) {
}
// Verify that modifying the file is caught.
-TEST_F(FileWatcherTest, ModifiedFile) {
+TEST_F(FileWatcherTest, MAYBE(ModifiedFile)) {
ASSERT_TRUE(WriteTestFile("content"));
SyncIfPOSIX();
@@ -157,7 +171,7 @@ TEST_F(FileWatcherTest, ModifiedFile) {
VerifyExpectedNumberOfNotifiedDelegates();
}
-TEST_F(FileWatcherTest, DeletedFile) {
+TEST_F(FileWatcherTest, MAYBE(DeletedFile)) {
ASSERT_TRUE(WriteTestFile("content"));
SyncIfPOSIX();
@@ -172,7 +186,7 @@ TEST_F(FileWatcherTest, DeletedFile) {
}
// Verify that letting the watcher go out of scope stops notifications.
-TEST_F(FileWatcherTest, Unregister) {
+TEST_F(FileWatcherTest, MAYBE(Unregister)) {
TestDelegate delegate(this);
{
@@ -211,7 +225,7 @@ class Deleter : public FileWatcher::Delegate {
} // anonymous namespace
// Verify that deleting a watcher during the callback doesn't crash.
-TEST_F(FileWatcherTest, DeleteDuringNotify) {
+TEST_F(FileWatcherTest, MAYBE(DeleteDuringNotify)) {
FileWatcher* watcher = new FileWatcher;
Deleter deleter(watcher, &loop_); // Takes ownership of watcher.
ASSERT_TRUE(watcher->Watch(test_file(), &deleter));
@@ -224,7 +238,7 @@ TEST_F(FileWatcherTest, DeleteDuringNotify) {
ASSERT_TRUE(deleter.watcher_.get() == NULL);
}
-TEST_F(FileWatcherTest, MultipleWatchersSingleFile) {
+TEST_F(FileWatcherTest, MAYBE(MultipleWatchersSingleFile)) {
FileWatcher watcher1, watcher2;
TestDelegate delegate1(this), delegate2(this);
ASSERT_TRUE(watcher1.Watch(test_file(), &delegate1));
@@ -242,5 +256,4 @@ TEST_F(FileWatcherTest, NonExistentDirectory) {
ASSERT_FALSE(watcher.Watch(test_file().AppendASCII("FileToWatch"), NULL));
}
-#endif
} // namespace