Repository: mesos
Updated Branches:
  refs/heads/master 2c1808685 -> 67017f136


Fixed flakiness in SlaveRecoveryTest/0.CleanupHTTPExecutor.

This change fixes the flakiness in this test. The issue was a race between the
`connected` callback being called before we did `process::spawn` to start the
process.

The details of the race that lead to the failure are as follows:
- We started the executor library inside the constructor of `TestExecutor`. The
  callback function did `process::defer(self(), &Self::connected)`
- The `connected` callback can be invoked by the Executor library before we got
  a chance to actually invoke `process::spawn` on the `TestExecutor` process
itself. This in can turn lead to the `dispatch` being silently dropped.

This change now starts the library inside the `initialize` function that is
gurranteed to be called after `process::spawn` is invoked.

Review: https://reviews.apache.org/r/43285/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/1af86559
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/1af86559
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/1af86559

Branch: refs/heads/master
Commit: 1af86559c3cf47159aa00c289208bbec50fd6df9
Parents: 2c18086
Author: Anand Mazumdar <[email protected]>
Authored: Mon Feb 8 15:32:22 2016 -0800
Committer: Vinod Kone <[email protected]>
Committed: Mon Feb 8 15:32:22 2016 -0800

----------------------------------------------------------------------
 src/examples/test_http_executor.cpp | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/1af86559/src/examples/test_http_executor.cpp
----------------------------------------------------------------------
diff --git a/src/examples/test_http_executor.cpp 
b/src/examples/test_http_executor.cpp
index 4916e0e..55a427f 100644
--- a/src/examples/test_http_executor.cpp
+++ b/src/examples/test_http_executor.cpp
@@ -60,10 +60,6 @@ public:
   TestExecutor(const FrameworkID& _frameworkId, const ExecutorID& _executorId)
     : frameworkId(_frameworkId),
       executorId(_executorId),
-      mesos(mesos::ContentType::PROTOBUF,
-            process::defer(self(), &Self::connected),
-            process::defer(self(), &Self::disconnected),
-            process::defer(self(), &Self::received, lambda::_1)),
       state(DISCONNECTED) {}
 
   void connected()
@@ -97,7 +93,7 @@ public:
       subscribe->add_unacknowledged_tasks()->MergeFrom(task);
     }
 
-    mesos.send(call);
+    mesos->send(call);
 
     process::delay(Seconds(1), self(), &Self::doReliableRegistration);
   }
@@ -129,7 +125,7 @@ public:
     // Capture the status update.
     updates[uuid] = call.update();
 
-    mesos.send(call);
+    mesos->send(call);
   }
 
   void received(queue<Event> events)
@@ -196,10 +192,22 @@ public:
     }
   }
 
+protected:
+  virtual void initialize()
+  {
+    // We initialize the library here to ensure that callbacks are only invoked
+    // after the process has spawned.
+    mesos.reset(new Mesos(
+        mesos::ContentType::PROTOBUF,
+        process::defer(self(), &Self::connected),
+        process::defer(self(), &Self::disconnected),
+        process::defer(self(), &Self::received, lambda::_1)));
+  }
+
 private:
   const FrameworkID frameworkId;
   const ExecutorID executorId;
-  Mesos mesos;
+  process::Owned<Mesos> mesos;
   enum State
   {
     CONNECTED,

Reply via email to