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

Unified Diff: runtime/vm/thread_test.cc

Issue 1397173004: Attempt to fix ThreadIterator_AddFindRemove flake (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/thread_test.cc
diff --git a/runtime/vm/thread_test.cc b/runtime/vm/thread_test.cc
index 51eaa5ff2a320464cbdde7c6d259ba448ce8930e..8e78dcadc120f7cb316d168ef68ddfbb9cfbc0af 100644
--- a/runtime/vm/thread_test.cc
+++ b/runtime/vm/thread_test.cc
@@ -435,24 +435,21 @@ TEST_CASE(ThreadIterator_Count) {
}
-TEST_CASE(ThreadIterator_FindSelf) {
- Thread* current = Thread::Current();
-
- bool found_self = false;
-
- {
- ThreadIterator ti;
- while (ti.HasNext()) {
- Thread* thread = ti.Next();
- EXPECT(thread != NULL);
- if (thread == current) {
- found_self = true;
- break;
- }
+static bool ThreadInList(Thread* thread) {
+ ThreadIterator it;
+ while (it.HasNext()) {
+ Thread* t = it.Next();
+ if (t == thread) {
+ return true;
}
}
+ return false;
+}
- EXPECT(found_self);
+
+TEST_CASE(ThreadIterator_FindSelf) {
+ Thread* current = Thread::Current();
+ EXPECT(ThreadInList(current));
}
@@ -469,34 +466,16 @@ void ThreadIteratorTestMain(uword parameter) {
ThreadIteratorTestParams* params =
reinterpret_cast<ThreadIteratorTestParams*>(parameter);
Isolate* isolate = params->isolate;
- ASSERT(isolate != NULL);
-
- Thread::EnterIsolateAsHelper(isolate);
+ EXPECT(isolate != NULL);
Thread* thread = Thread::Current();
- ASSERT(thread != NULL);
+ EXPECT(thread != NULL);
+ MonitorLocker ml(params->monitor);
params->spawned_thread = thread;
params->spawned_thread_join_id = OSThread::GetCurrentThreadJoinId();
-
- {
- MonitorLocker ml(params->monitor);
- ml.Notify();
- }
-
- {
- bool found_self = false;
- ThreadIterator it;
- while (it.HasNext()) {
- Thread* t = it.Next();
- if (t == thread) {
- found_self = true;
- break;
- }
- }
- EXPECT(found_self);
- }
-
- Thread::ExitIsolateAsHelper();
+ EXPECT(params->spawned_thread_join_id != OSThread::kInvalidThreadJoinId);
+ EXPECT(ThreadInList(thread));
+ ml.Notify();
}
@@ -523,17 +502,17 @@ TEST_CASE(ThreadIterator_AddFindRemove) {
OSThread::Join(params.spawned_thread_join_id);
}
- ThreadIterator it;
- bool found_spawned_thread = false;
- while (it.HasNext()) {
- Thread* t = it.Next();
- if (t == params.spawned_thread) {
- found_spawned_thread = true;
+ for (intptr_t i = 0; i < 10; i++) {
+ // Sleep for 10 milliseconds.
+ OS::Sleep(10);
+ if (!ThreadInList(params.spawned_thread)) {
break;
}
}
- EXPECT(!found_spawned_thread);
+ EXPECT(!ThreadInList(params.spawned_thread))
+
+ delete params.monitor;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698