Repository: mesos Updated Branches: refs/heads/master 012c9eeeb -> 1d86932ce
Fixed race in hook self-message loop and reenabled VerifySlaveLaunchExecutorHook test Coordinating events across the library border is hard as we want to avoid exporting additional symbols between the test and the module code. To migitate this, the VerifySlaveLaunchExecutorHook used a technique where it creates a libprocess actors in-place and sends a message to itself. This can be caught by a message filter in the shared libprocess instance and the test code can synchronize over this, to make sure certain module code was executed. However, the in-place actor could (potentially) shutdown before the message was received (and thus, didn't execute the filter). This patch installs a message handler in the in-place actor and only shuts down the actors when the message has been received. Review: https://reviews.apache.org/r/38574 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f6706e89 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f6706e89 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f6706e89 Branch: refs/heads/master Commit: f6706e8921569ce5cda63585ca85d82a4d2459c7 Parents: 012c9ee Author: Niklas Nielsen <[email protected]> Authored: Wed Sep 23 15:36:52 2015 -0700 Committer: Niklas Q. Nielsen <[email protected]> Committed: Wed Sep 23 15:36:52 2015 -0700 ---------------------------------------------------------------------- src/examples/test_hook_module.cpp | 37 +++++++++++++++++++++++++++++++--- src/tests/hook_tests.cpp | 2 +- 2 files changed, 35 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/f6706e89/src/examples/test_hook_module.cpp ---------------------------------------------------------------------- diff --git a/src/examples/test_hook_module.cpp b/src/examples/test_hook_module.cpp index 0dc74d6..5c4d71a 100644 --- a/src/examples/test_hook_module.cpp +++ b/src/examples/test_hook_module.cpp @@ -48,13 +48,36 @@ const char* testRemoveLabelKey = "MESOS_Test_Remove_Label"; class HookProcess : public ProtobufProcess<HookProcess> { public: - Future<Nothing> signal() + void initialize() { + install<internal::HookExecuted>( + &HookProcess::handler, + &internal::HookExecuted::module); + } + + void signal() + { + LOG(INFO) << "HookProcess emitting signal"; + internal::HookExecuted message; message.set_module("org_apache_mesos_TestHook"); send(self(), message); - return Nothing(); } + + void handler(const process::UPID& from, const string& module) + { + LOG(INFO) << "HookProcess caught signal: " << module; + + promise.set(Nothing()); + } + + Future<Nothing> await() + { + return promise.future(); + } + +private: + process::Promise<Nothing> promise; }; @@ -163,7 +186,15 @@ public: // indicates successful execution of this hook. HookProcess hookProcess; process::spawn(&hookProcess); - process::dispatch(hookProcess, &HookProcess::signal).await(); + Future<Nothing> future = + process::dispatch(hookProcess, &HookProcess::await); + + process::dispatch(hookProcess, &HookProcess::signal); + + // Make sure we don't terminate the process before the message self-send has + // completed. + future.await(); + process::terminate(hookProcess); process::wait(hookProcess); http://git-wip-us.apache.org/repos/asf/mesos/blob/f6706e89/src/tests/hook_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/hook_tests.cpp b/src/tests/hook_tests.cpp index b23a587..f85d917 100644 --- a/src/tests/hook_tests.cpp +++ b/src/tests/hook_tests.cpp @@ -259,7 +259,7 @@ TEST_F(HookTest, VerifySlaveExecutorEnvironmentDecorator) // Test executor environment decorator hook and remove executor hook // for slave. We expect the environment-decorator hook to create a // temporary file and the remove-executor hook to delete that file. -TEST_F(HookTest, DISABLED_VerifySlaveLaunchExecutorHook) +TEST_F(HookTest, VerifySlaveLaunchExecutorHook) { master::Flags masterFlags = CreateMasterFlags();
