You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2023/06/01 18:34:00 UTC

[jira] [Commented] (NIFI-11603) Address problematic/flaky unit tests

    [ https://issues.apache.org/jira/browse/NIFI-11603?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17728453#comment-17728453 ] 

ASF subversion and git services commented on NIFI-11603:
--------------------------------------------------------

Commit 50811660d00b4bcfcb431f9897807352b947813a in nifi's branch refs/heads/main from Mark Payne
[ https://gitbox.apache.org/repos/asf?p=nifi.git;h=50811660d0 ]

NIFI-11603 Refactored Socket-based tests to use Dynamic Ports

- Removed NetworkUtils methods for getting available ports
- Updated Socket-based components to support using 0 to listen on a random available port for improved test reliability

This closes #7299

Signed-off-by: David Handermann <ex...@apache.org>


> 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: 1h 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)