Fix rare hang in dev_server_wrapper.py.

Once in a long while, dev_server_wrapper would hang when shutting down the
devserver, which would cause VM tests on the builders to fail.

This CL includes the test script used to reproduce the original problem
(which reproduced on the 435th shutdown), and to verify the fix (which ran
though 23,342 iterations before I killed it).

BUG=chromium:242470
TEST=Ran test script though over 23,000 start/stop iterations without hanging.

Change-Id: I17943701361c3d5ae2f63abf25904d797b46e507
Reviewed-on: https://gerrit.chromium.org/gerrit/56635
Commit-Queue: Don Garrett <dgarrett@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
diff --git a/lib/dev_server_wrapper.py b/lib/dev_server_wrapper.py
index 33032ab..4ccf528 100644
--- a/lib/dev_server_wrapper.py
+++ b/lib/dev_server_wrapper.py
@@ -6,7 +6,7 @@
 """
 
 import os
-import threading
+import multiprocessing
 import re
 import sys
 import time
@@ -49,14 +49,14 @@
   """Thrown when the devserver fails to start up correctly."""
 
 
-class DevServerWrapper(threading.Thread):
+class DevServerWrapper(multiprocessing.Process):
   """A Simple wrapper around a dev server instance."""
 
   def __init__(self, test_root):
     self.proc = None
     self.test_root = test_root
     self._log_filename = os.path.join(test_root, 'dev_server.log')
-    threading.Thread.__init__(self)
+    multiprocessing.Process.__init__(self)
 
   def run(self):
     # Kill previous running instance of devserver if it exists.
diff --git a/lib/dev_server_wrapper_stress_test.py b/lib/dev_server_wrapper_stress_test.py
new file mode 100755
index 0000000..0b75c3b
--- /dev/null
+++ b/lib/dev_server_wrapper_stress_test.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python
+
+# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Stress test for dev_server_wrapper.
+
+Test script runs forever stressing the ability to start and stop the
+dev_server_wrapper. Even very rare hangs will cause significant build flake.
+"""
+
+import sys
+
+import constants
+sys.path.append(constants.CROSUTILS_LIB_DIR)
+sys.path.append(constants.CROS_PLATFORM_ROOT)
+sys.path.append(constants.SOURCE_ROOT)
+
+from crostestutils.lib import dev_server_wrapper
+
+i = 0
+while True:
+  i += 1
+  print 'Iteration {}'.format(i)
+  wrapper = dev_server_wrapper.DevServerWrapper('/tmp')
+  print 'Starting'
+  wrapper.start()
+  print 'Waiting for Started'
+  wrapper.WaitUntilStarted()
+  print 'Stopping'
+  wrapper.Stop()