Skip to content

Commit

Permalink
Cleaned up timeouts on Jython. Related to #1931.
Browse files Browse the repository at this point in the history
Now that IronPython has its own timeout implementation, Jython was the
only one using timeoutthread module and nobody used stoppablethread it
used when not run on Jython. Moved Jython related stuff to new module
and removed not used modules.

Jython and IronPython thread usage is very similar, and it would be
pretty easy to create facades to avoid duplication. Decided to keep
them separate because that would require more code, including a new
module, and added abstraction level would make things a little more
complicated.
  • Loading branch information
pekkaklarck committed Feb 25, 2015
1 parent b40b8bf commit cdfb783
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 144 deletions.
1 change: 0 additions & 1 deletion atest/robot/core/timeouts.robot
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*** Settings ***
Documentation Tests for test case and user keyword timeouts. Using timeouts with variables and invalid timeouts is tested in 'metadata.html'. It seems that on Cygwin Python tests now and then fail with an error message "error: can't allocate lock"
Suite Setup Run Tests ${EMPTY} core/timeouts.robot
Suite Teardown Remove Directory ${TIMEOUT TEMP} recursive
Force Tags regression
Expand Down
2 changes: 1 addition & 1 deletion src/robot/running/timeouts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
if IRONPYTHON:
from .ironpython import Timeout
elif JYTHON:
from .timeoutthread import Timeout
from .jython import Timeout
elif WINDOWS:
from .timeoutwin import Timeout
else:
Expand Down
11 changes: 6 additions & 5 deletions src/robot/running/timeouts/ironpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@
class Timeout(object):

def __init__(self, timeout, error):
self._timeout = timeout * 1000
self._timeout = timeout
self._error = error

def execute(self, runnable):
runner = Runner(runnable)
thread = Thread(ThreadStart(runner))
thread.IsBackground = True
thread.Start()
if thread.Join(self._timeout):
return runner.get_result()
thread.Abort()
raise TimeoutError(self._error)
if not thread.Join(self._timeout * 1000):
thread.Abort()
raise TimeoutError(self._error)
return runner.get_result()


class Runner(object):
Expand Down
56 changes: 56 additions & 0 deletions src/robot/running/timeouts/jython.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2008-2015 Nokia Solutions and Networks
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

from java.lang import Thread, Runnable

from robot.errors import TimeoutError


class Timeout(object):

def __init__(self, timeout, error):
self._timeout = timeout
self._error = error

def execute(self, runnable):
runner = Runner(runnable)
thread = Thread(runner, name='RobotFrameworkTimeoutThread')
thread.setDaemon(True)
thread.start()
thread.join(int(self._timeout * 1000))
if thread.isAlive():
thread.stop()
raise TimeoutError(self._error)
return runner.get_result()


class Runner(Runnable):

def __init__(self, runnable):
self._runnable = runnable
self._result = None
self._error = None

def run(self):
try:
self._result = self._runnable()
except:
self._error = sys.exc_info()

def get_result(self):
if not self._error:
return self._result
raise self._error[0], self._error[1], self._error[2]
59 changes: 0 additions & 59 deletions src/robot/running/timeouts/stoppablethread.py

This file was deleted.

78 changes: 0 additions & 78 deletions src/robot/running/timeouts/timeoutthread.py

This file was deleted.

0 comments on commit cdfb783

Please sign in to comment.