[ 
https://issues.apache.org/jira/browse/NIFI-11603?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Mark Payne updated NIFI-11603:
------------------------------
    Status: Patch Available  (was: Open)

> Address problematic/flaky unit tests
> ------------------------------------
>
>                 Key: NIFI-11603
>                 URL: https://issues.apache.org/jira/browse/NIFI-11603
>             Project: Apache NiFi
>          Issue Type: Bug
>          Components: Extensions
>            Reporter: Mark Payne
>            Assignee: Mark Payne
>            Priority: Major
>             Fix For: 1.latest, 2.latest
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> We have many tests throughout the codebase that use 
> NetworkUtils.getAvailablePort / getAvailableTcpPort / getAvailableUdpPort.
> These util methods need to be removed and not used. They are a very bad 
> practice that result in intermittent failures. These methods work by creating 
> a ServerSocket using Port 0, starting it, then determining the port that it's 
> listening on. Then the ServerSocket is closed and the port it was listening 
> on was returned so that it can be used for another server to be started.
> This is problematic for two reasons. Firstly, there's no reason to think that 
> the port will be available when the next server is started - there are all 
> sorts of OS settings for how long the sockets are kept alive, etc.
> Secondly, another process, or another unit test using the same mechanism may 
> well start as soon as the ServerSocket is closed and before the second server 
> is started.
> Either of these conditions will cause a BindException, which we see 
> frequently in failed unit tests.
> The proper mechanism to handle this is to start the desired server using port 
> 0 to begin with, and then asking the server which port it's listening on once 
> it's started.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to