mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Backed out changeset de3f062c9a99 (bug 1231981)
This commit is contained in:
parent
94cebd7b33
commit
1fe3914869
@ -153,12 +153,3 @@ TEST_HARNESS_FILES.testing.mochitest.tests.testing.mochitest.tests['MochiKit-1.4
|
||||
'tests/MochiKit-1.4.2/MochiKit/Test.js',
|
||||
'tests/MochiKit-1.4.2/MochiKit/Visual.js',
|
||||
]
|
||||
|
||||
TEST_HARNESS_FILES.testing.mochitest.iceserver += [
|
||||
'/testing/tools/iceserver/iceserver.py',
|
||||
]
|
||||
|
||||
TEST_HARNESS_FILES.testing.mochitest.websocketprocessbridge += [
|
||||
'/testing/tools/websocketprocessbridge/websocketprocessbridge.py',
|
||||
]
|
||||
|
||||
|
@ -528,7 +528,6 @@ class MochitestBase(object):
|
||||
self.update_mozinfo()
|
||||
self.server = None
|
||||
self.wsserver = None
|
||||
self.websocketProcessBridge = None
|
||||
self.sslTunnel = None
|
||||
self._active_tests = None
|
||||
self._locations = None
|
||||
@ -806,34 +805,6 @@ class MochitestBase(object):
|
||||
with open(options.pidFile + ".xpcshell.pid", 'w') as f:
|
||||
f.write("%s" % self.server._process.pid)
|
||||
|
||||
def startWebsocketProcessBridge(self, options):
|
||||
"""Create a websocket server that can launch various processes that
|
||||
JS needs (eg; ICE server for webrtc testing)
|
||||
"""
|
||||
|
||||
command = [sys.executable,
|
||||
os.path.join("websocketprocessbridge",
|
||||
"websocketprocessbridge.py")]
|
||||
self.websocketProcessBridge = mozprocess.ProcessHandler(command,
|
||||
cwd=SCRIPT_DIR)
|
||||
self.websocketProcessBridge.run()
|
||||
self.log.info("runtests.py | websocket/process bridge pid: %d"
|
||||
% self.websocketProcessBridge.pid)
|
||||
|
||||
# ensure the server is up, wait for at most ten seconds
|
||||
for i in range(1,100):
|
||||
try:
|
||||
sock = socket.create_connection(("127.0.0.1", 8191))
|
||||
sock.close()
|
||||
break
|
||||
except:
|
||||
time.sleep(0.1)
|
||||
else:
|
||||
self.log.error("runtests.py | Timed out while waiting for "
|
||||
"websocket/process bridge startup.")
|
||||
self.stopServers()
|
||||
sys.exit(1)
|
||||
|
||||
def startServers(self, options, debuggerInfo, ignoreSSLTunnelExts=False):
|
||||
# start servers and set ports
|
||||
# TODO: pass these values, don't set on `self`
|
||||
@ -851,7 +822,6 @@ class MochitestBase(object):
|
||||
|
||||
self.startWebServer(options)
|
||||
self.startWebSocketServer(options, debuggerInfo)
|
||||
self.startWebsocketProcessBridge(options)
|
||||
|
||||
# start SSL pipe
|
||||
self.sslTunnel = SSLTunnel(
|
||||
@ -892,13 +862,6 @@ class MochitestBase(object):
|
||||
except Exception:
|
||||
self.log.critical('Exception stopping ssltunnel')
|
||||
|
||||
if self.websocketProcessBridge is not None:
|
||||
try:
|
||||
self.log.info('Stopping websocketProcessBridge')
|
||||
self.websocketProcessBridge.kill()
|
||||
except Exception:
|
||||
self.log.critical('Exception stopping websocketProcessBridge')
|
||||
|
||||
def copyExtraFilesToProfile(self, options):
|
||||
"Copy extra files or dirs specified on the command line to the testing profile."
|
||||
for f in options.extraProfileFiles:
|
||||
|
@ -1,100 +0,0 @@
|
||||
# vim: set ts=4 et sw=4 tw=80
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
from twisted.internet import protocol, reactor
|
||||
from twisted.internet.task import LoopingCall
|
||||
import txws
|
||||
import psutil
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
# maps a command issued via websocket to running an executable with args
|
||||
commands = {
|
||||
'iceserver' : [sys.executable,
|
||||
"-u",
|
||||
os.path.join("iceserver", "iceserver.py")]
|
||||
}
|
||||
|
||||
class ProcessSide(protocol.ProcessProtocol):
|
||||
"""Handles the spawned process (I/O, process termination)"""
|
||||
|
||||
def __init__(self, socketSide):
|
||||
self.socketSide = socketSide
|
||||
|
||||
def outReceived(self, data):
|
||||
if self.socketSide:
|
||||
lines = data.splitlines()
|
||||
for line in lines:
|
||||
self.socketSide.transport.write(line)
|
||||
|
||||
def errReceived(self, data):
|
||||
self.outReceived(data)
|
||||
|
||||
def processEnded(self, reason):
|
||||
if self.socketSide:
|
||||
self.outReceived(str(reason))
|
||||
self.socketSide.processGone()
|
||||
|
||||
def socketGone(self):
|
||||
self.socketSide = None
|
||||
self.transport.loseConnection()
|
||||
self.transport.signalProcess("KILL")
|
||||
|
||||
|
||||
class SocketSide(protocol.Protocol):
|
||||
"""
|
||||
Handles the websocket (I/O, closed connection), and spawning the process
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.processSide = None
|
||||
|
||||
def dataReceived(self, data):
|
||||
if not self.processSide:
|
||||
self.processSide = ProcessSide(self)
|
||||
# We deliberately crash if |data| isn't on the "menu",
|
||||
# or there is some problem spawning.
|
||||
reactor.spawnProcess(self.processSide,
|
||||
commands[data][0],
|
||||
commands[data],
|
||||
env=os.environ)
|
||||
|
||||
def connectionLost(self, reason):
|
||||
if self.processSide:
|
||||
self.processSide.socketGone()
|
||||
|
||||
def processGone(self):
|
||||
self.processSide = None
|
||||
self.transport.loseConnection()
|
||||
|
||||
|
||||
class ProcessSocketBridgeFactory(protocol.Factory):
|
||||
"""Builds sockets that can launch/bridge to a process"""
|
||||
|
||||
def buildProtocol(self, addr):
|
||||
return SocketSide()
|
||||
|
||||
# Parent process could have already exited, so this is slightly racy. Only
|
||||
# alternative is to set up a pipe between parent and child, but that requires
|
||||
# special cooperation from the parent.
|
||||
parent_process = psutil.Process(os.getpid()).parent()
|
||||
|
||||
def check_parent():
|
||||
""" Checks if parent process is still alive, and exits if not """
|
||||
if not parent_process.is_running():
|
||||
print("websocket/process bridge exiting because parent process is gone")
|
||||
reactor.stop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
parent_checker = LoopingCall(check_parent)
|
||||
parent_checker.start(1)
|
||||
|
||||
bridgeFactory = ProcessSocketBridgeFactory()
|
||||
reactor.listenTCP(8191, txws.WebSocketFactory(bridgeFactory))
|
||||
print("websocket/process bridge listening on port 8191")
|
||||
reactor.run()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user