Bug 169048 - webkitpy: SimulatorProcess requires a defined worker_number
Summary: webkitpy: SimulatorProcess requires a defined worker_number
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jonathan Bedard
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-01 11:23 PST by Jonathan Bedard
Modified: 2017-03-02 12:30 PST (History)
3 users (show)

See Also:


Attachments
Patch (1.51 KB, patch)
2017-03-01 11:25 PST, Jonathan Bedard
dbates: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Bedard 2017-03-01 11:23:27 PST
SimulatorProcess requires it's worker number to be defined, but also defines a default value.  Since SimulatorProcess inherits from ServerProcess and we do not wish to change the signature of ServerProcess, SimulatorProcess should throw an exception in it's constructor if worker_number is undefined.
Comment 1 Jonathan Bedard 2017-03-01 11:25:15 PST
Created attachment 303089 [details]
Patch
Comment 2 Daniel Bates 2017-03-02 12:15:58 PST
Comment on attachment 303089 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=303089&action=review

> Tools/Scripts/webkitpy/port/simulator_process.py:61
> +        if not worker_number is None:
> +            raise Exception('worker_number must be defined when initializing {}'.format(self.__class__.__name__))

We should remove the default value for worker_number from the function signature such that it read:
 
def __init__(self, port_obj, name, cmd, env=None, universal_newlines=False, treat_no_data_as_crash=False, worker_number):

Then we can remove this code. Instantiating a SimulatorProcess without a worker_number will raise a Python TypeError.
Comment 3 Jonathan Bedard 2017-03-02 12:30:46 PST
Comment on attachment 303089 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=303089&action=review

>> Tools/Scripts/webkitpy/port/simulator_process.py:61
>> +            raise Exception('worker_number must be defined when initializing {}'.format(self.__class__.__name__))
> 
> We should remove the default value for worker_number from the function signature such that it read:
>  
> def __init__(self, port_obj, name, cmd, env=None, universal_newlines=False, treat_no_data_as_crash=False, worker_number):
> 
> Then we can remove this code. Instantiating a SimulatorProcess without a worker_number will raise a Python TypeError.

You can not have a function argument which requires a value after ones which define default ones in Python.

I don't think we want to do the refactor to change the signature of ServerProcess's initializer because I've seen commands like this:
ServerProcess(port, 'Example Process', ['ls'], environment)
throughout webkitpy.  If we want an exception thrown as early as possible, I think raising an exception here is the best technique.  Otherwise, we could just allow the undefined worker_number to fail later, which would be with a Python exception as well when we attempt to access the device_for_worker_number_map.