Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(606)

Unified Diff: base/synchronization/waitable_event_unittest.cc

Issue 999753005: Make sure that WaitableEvent::TimedWait works fine with large timeouts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/synchronization/waitable_event_posix.cc ('k') | base/synchronization/waitable_event_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/synchronization/waitable_event_unittest.cc
diff --git a/base/synchronization/waitable_event_unittest.cc b/base/synchronization/waitable_event_unittest.cc
index abba9356bb17a2e967863a2e06e0a6a4dfaed092..392a923cf14e1ab284ed9cb0b7f002063bdb0749 100644
--- a/base/synchronization/waitable_event_unittest.cc
+++ b/base/synchronization/waitable_event_unittest.cc
@@ -73,29 +73,27 @@ TEST(WaitableEventTest, WaitManyShortcut) {
class WaitableEventSignaler : public PlatformThread::Delegate {
public:
- WaitableEventSignaler(double seconds, WaitableEvent* ev)
- : seconds_(seconds),
- ev_(ev) {
+ WaitableEventSignaler(TimeDelta delay, WaitableEvent* event)
+ : delay_(delay),
+ event_(event) {
}
void ThreadMain() override {
- PlatformThread::Sleep(TimeDelta::FromSecondsD(seconds_));
- ev_->Signal();
+ PlatformThread::Sleep(delay_);
+ event_->Signal();
}
private:
- const double seconds_;
- WaitableEvent *const ev_;
+ const TimeDelta delay_;
+ WaitableEvent* event_;
};
+// Tests that a WaitableEvent can be safely deleted when |Wait| is done without
+// additional synchronization.
TEST(WaitableEventTest, WaitAndDelete) {
- // This test tests that if a WaitableEvent can be safely deleted
- // when |Wait| is done without additional synchrnization.
- // If this test crashes, it is a bug.
-
WaitableEvent* ev = new WaitableEvent(false, false);
- WaitableEventSignaler signaler(0.01, ev);
+ WaitableEventSignaler signaler(TimeDelta::FromMilliseconds(10), ev);
PlatformThreadHandle thread;
PlatformThread::Create(0, &signaler, &thread);
@@ -105,16 +103,14 @@ TEST(WaitableEventTest, WaitAndDelete) {
PlatformThread::Join(thread);
}
+// Tests that a WaitableEvent can be safely deleted when |WaitMany| is done
+// without additional synchronization.
TEST(WaitableEventTest, WaitMany) {
- // This test tests that if a WaitableEvent can be safely deleted
- // when |WaitMany| is done without additional synchrnization.
- // If this test crashes, it is a bug.
-
WaitableEvent* ev[5];
for (unsigned i = 0; i < 5; ++i)
ev[i] = new WaitableEvent(false, false);
- WaitableEventSignaler signaler(0.01, ev[2]);
+ WaitableEventSignaler signaler(TimeDelta::FromMilliseconds(10), ev[2]);
PlatformThreadHandle thread;
PlatformThread::Create(0, &signaler, &thread);
@@ -127,4 +123,22 @@ TEST(WaitableEventTest, WaitMany) {
EXPECT_EQ(2u, index);
}
+// Tests that using TimeDelta::Max() on TimedWait() is not the same as passing
+// a timeout of 0. (crbug.com/465948)
+TEST(WaitableEventTest, TimedWait) {
+ WaitableEvent* ev = new WaitableEvent(false, false);
+
+ TimeDelta thread_delay = TimeDelta::FromMilliseconds(10);
+ WaitableEventSignaler signaler(thread_delay, ev);
+ PlatformThreadHandle thread;
+ TimeTicks start = TimeTicks::Now();
+ PlatformThread::Create(0, &signaler, &thread);
+
+ ev->TimedWait(TimeDelta::Max());
+ EXPECT_GE(TimeTicks::Now() - start, thread_delay);
+ delete ev;
+
+ PlatformThread::Join(thread);
+}
+
} // namespace base
« no previous file with comments | « base/synchronization/waitable_event_posix.cc ('k') | base/synchronization/waitable_event_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698