Branch: refs/heads/master
Home: https://github.com/pgjdbc/pgjdbc
Commit: 6e453aaead9dc15bf648cb490e6bbef6a1a2c3a7
https://github.com/pgjdbc/pgjdbc/commit/6e453aaead9dc15bf648cb490e6bbef6a1a2c3a7
Author: Daisuke <higuchi.daisuke@jp.fujitsu.com>
Date: 2022-07-14 (Thu, 14 Jul 2022)
Changed paths:
M pgjdbc/src/test/java/org/postgresql/test/jdbc2/ConnectTimeoutTest.java
Log Message:
-----------
test: fix ConnectTimeoutTest to hadle SocketTimeoutException and NoRouteToHostException correctly (#2566)
I think the ConnectTimeoutTest is not working as expected.
First of all, my expectation was as follows:
- When NoRouteToHostException is thrown, this test will be ignored and SKIPed.
- When SocketTimeoutException is thrown, this test will be succeeded.
However, the actual behavior was as follows:
- When NoRouteToHostException is thrown, this test will be failed.
- When SocketTimeoutException is thrown, this test will be ignored and SKIPed.
Note:
In my environment, NoRouteToHostException is thrown, so the test always fails.
In the community's CI environment, SocketTimeoutException is probably thrown, so this test is always SKIPed, I think.
This is because Assume.assumeTrue() is used instead of Assume.assumeFalse() to handle NoRouteToHostException.
The JUnit documentation says:
```
assumeTrue
public static void assumeTrue(boolean b)
If called with an expression evaluating to false, the test will halt and be ignored.
```
https://junit.org/junit4/javadoc/4.13/org/junit/Assume.html#assumeTrue(boolean)
Therefore, in Assume.assumeTrue(), when the expression evaluating becomes "false",
the test will halt and be ignored.
When NoRouteToHostException is thrown, the expression evaluating becomes "true"
and the test proceeds to the next step,
and fails with assertTrue(e.getCause() instanceof SocketTimeoutException).
When SocketTimeoutException is thrown, the test halts at Assume.assumeTrue()
because the expression evaluating is "false".
Now, in Assume.assumeFalse(), when the expression evaluating becomes "true",
the test will halt and be ignored.
When NoRouteToHostException is thrown, the test halts at Assume.assumeFalse()
because the expression evaluating is "true".
When SocketTimeoutException is thrown, the expression evaluating becomes "false",
so the test continues to the next step and eventually succeeds.