Uploaded image for project: 'Apache NiFi'
  1. Apache NiFi
  2. NIFI-11603

Refactor Unstable Socket-based Tests

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 2.0.0-M1, 1.22.0
    • Extensions
    • None

    Description

      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.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            markap14 Mark Payne
            markap14 Mark Payne
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 10m
                1h 10m

                Slack

                  Issue deployment