pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Daisuke <noreply@github.com>
To: pgsql-jdbc@lists.postgresql.org
Subject: [pgjdbc/pgjdbc] 6e453a: test: fix ConnectTimeoutTest to hadle SocketTimeou...
Date: Thu, 14 Jul 2022 05:22:07 -0700
Message-ID: <pgjdbc/pgjdbc/push/refs/heads/master/4c7a09-6e453a@github.com> (raw)

  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.







Message-ID: <pgjdbc/pgjdbc/push/refs/heads/master/4c7a09-6e453a@github.com>
Permalink:  ../pgjdbc%2Fpgjdbc%2Fpush%2Frefs%2Fheads%2Fmaster%2F4c7a09-6e453a@github.com/
Also on:    postgresql.org/message-id/pgjdbc/pgjdbc/push/refs/heads/master/4c7a09-6e453a@github.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: noreply@github.com
  Subject: Re: [pgjdbc/pgjdbc] 6e453a: test: fix ConnectTimeoutTest to hadle SocketTimeou...
  In-Reply-To: <pgjdbc/pgjdbc/push/refs/heads/master/4c7a09-6e453a@github.com>
  References: <pgjdbc/pgjdbc/push/refs/heads/master/4c7a09-6e453a@github.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox