RFR: 8293696: java/nio/channels/DatagramChannel/SelectWhenRefused.java fails with "Unexpected wakeup" [v2]
Daniel Fuchs
dfuchs at openjdk.org
Fri Oct 28 08:34:31 UTC 2022
On Thu, 27 Oct 2022 18:53:19 GMT, Mark Sheppard <msheppar at openjdk.org> wrote:
>> I don't think so - scenario 2 is the one that expect the PortUnreachableException - so the wakeup is expected there and the read is expected to throw PortUnreadableException. The other two scenario are expected to timeout of the select with n == 0;
>
> I mean the actual testing of the received message -- scenario performs the read, and expects an Exception but if it gets a message, which like the other scenarios it shouldn't, then the test of that message should be the same across all 3 scenarios ?
> scenario 1 and 3 test if they receive what has been sent then retry, while scenario 2 will throw a RuntimeException if it receives what it has sent. This seems inconsistent.
>
> Maybe change the send message to be completely unique to this test, there maybe other DatagramSocket or Channel tests that have message containing "Greetings"
No I believe scenario 2 is different - but you are right - it would be more correct to replace lines 90-91 with this:
// BindException will be thrown if another service is using
// our expected refuser port, cannot run just exit.
DatagramChannel.open().bind(refuser).close();
throw new RuntimeException("PortUnreachableException not raised");
In other words: we are connected - so we could only receive a message from something bound to the refuser's port. So check whether that port is still unbound, and if so, complain that PortUnreachableException should have been received.
Note that there still might be a race condition here because something could have transiently bound to the refuser and then released it. But the window of opportunity for the race should be smaller.
Whether we should `throw new RuntimeException("PortUnreachableException not raised");` or simply `continue` and try again could be discussed.
-------------
PR: https://git.openjdk.org/jdk/pull/10851
More information about the nio-dev
mailing list