I've come across a few cases I would like to test that require the test performing multiple actions simultaneously.
In most cases, it is sufficient to start one or more tasks and check their output. However, it would nice to be able to use multiple threads.
To experiment with this, I wrote a small library that spawns new threads to run arbitrary keywords in the background, and allows the main thread to wait for the background tasks to finish (using thread.join())
The keyword to run is passed in as a parameter, and robot's BuiltIn library is used to resolve and run the specified keyword.
Right away, I ran into two issues:
- Log messages generated by background threads will get scrambled into the main thread's output
- Starting and ending keywords outside of the main thread causes a strange ValueError
ValueError: I/O operation on closed file
Traceback (most recent call last):
File "C:\RobotAsyncLibrary.py", line 58, in wait_for_background_keywords
thread.join(timeout=timeout)
File "C:\Python27\lib\StringIO.py", line 213, in write
_complain_ifclosed(self.closed)
File "C:\Python27\lib\StringIO.py", line 40, in _complain_ifclosed
raise ValueError, "I/O operation on closed file"
I think the 2nd problem arises because the keywords in the background are closing the stream to the log file(s) when they finish.
This is probably just a limitation inherent in Robot, but I figured it was worth asking. Is there a way around this?