Start edit monitor only when the feature is enabled
Check the env variable to determine whether the edit monitor feature is
enabled and only start the edit monitor if it is enabled, otherwise exit
directly. This helps to roll out the feature gradually.
Test: atest edit_monitor_utils_test atest daemon_manager_test
Bug: 365617369
Change-Id: I03fb494e1f62712efaf0bb05de8859e0118702bf
diff --git a/tools/edit_monitor/daemon_manager_test.py b/tools/edit_monitor/daemon_manager_test.py
index e132000..407d94e 100644
--- a/tools/edit_monitor/daemon_manager_test.py
+++ b/tools/edit_monitor/daemon_manager_test.py
@@ -81,6 +81,8 @@
# Sets the tempdir under the working dir so any temp files created during
# tests will be cleaned.
tempfile.tempdir = self.working_dir.name
+ self.patch = mock.patch.dict(os.environ, {'ENABLE_EDIT_MONITOR': 'true'})
+ self.patch.start()
def tearDown(self):
# Cleans up any child processes left by the tests.
@@ -88,6 +90,7 @@
self.working_dir.cleanup()
# Restores tempdir.
tempfile.tempdir = self.original_tempdir
+ self.patch.stop()
super().tearDown()
def test_start_success_with_no_existing_instance(self):
@@ -129,6 +132,15 @@
dm = daemon_manager.DaemonManager(TEST_BINARY_FILE)
dm.start()
+
+ # Verify no daemon process is started.
+ self.assertIsNone(dm.daemon_process)
+
+ @mock.patch.dict(os.environ, {'ENABLE_EDIT_MONITOR': 'false'}, clear=True)
+ def test_start_return_directly_if_disabled(self):
+ dm = daemon_manager.DaemonManager(TEST_BINARY_FILE)
+ dm.start()
+
# Verify no daemon process is started.
self.assertIsNone(dm.daemon_process)
@@ -137,6 +149,7 @@
'/google/cog/cloud/user/workspace/edit_monitor'
)
dm.start()
+
# Verify no daemon process is started.
self.assertIsNone(dm.daemon_process)