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

Unified Diff: chrome/test/mini_installer/process_visitor.py

Issue 2747023002: Cleanup machine based on the state in configuration file for mini installer test.
Patch Set: fix gni file Created 3 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
Index: chrome/test/mini_installer/process_visitor.py
diff --git a/chrome/test/mini_installer/process_visitor.py b/chrome/test/mini_installer/process_visitor.py
new file mode 100644
index 0000000000000000000000000000000000000000..8fa1e345b10b9d8c672bdad20bcd81691ecf30af
--- /dev/null
+++ b/chrome/test/mini_installer/process_visitor.py
@@ -0,0 +1,48 @@
+# Copyright 2017 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import chrome_helper
+import visitor
+
+class ProcessVisitor(visitor.Visitor):
+ """ Visitor for Processes entry in property.
+ """
+ def _VisitEntry(self, entry_name, entry_value):
+ """ Check whether a process is running or not.
+
+ Args:
+ 'entry_name' - A string represents the path to the process being
+ verified.
+ 'entry_value' - A dictionary with the following key and value:
+ 'running': a boolean indicating whether the process
+ should be running.
+ """
+ running_process_paths = [path for (_, path) in
+ chrome_helper.GetProcessIDAndPathPairs()]
+ process_path = self._variable_expander.Expand(entry_name)
+ is_running = process_path in running_process_paths
+ self._HandleProcess(is_running, entry_value['running'], process_path)
+
+ def _HandleProcess(self, is_running, should_process_run, process_path):
+ """ Abstract function to check process.
+
+ Args:
+ is_running: A boolean represents whether the process is running.
+ should_process_run: A boolean represents whether the process should
+ keep running.
+ process_path: A string represents the path to the process.
+ """
+ raise NotImplementedError()
+
+class ProcessVerifier(ProcessVisitor):
+ """Verifies that the running processes match the expectation dictionaries."""
+ def _HandleProcess(self, is_running, should_process_run, process_path):
+ """ Overridden ProcessVisitor._HandleProcess to verify a process state.
+ """
+ error_message = ""
+ if is_running:
+ error_message = 'Process %s is running' % process_path
+ else:
+ error_message = 'Process %s is not running' % process_path
+ assert should_process_run == is_running, error_message

Powered by Google App Engine
This is Rietveld 408576698