Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oBxrB-0004EV-C0 for pgsql-jdbc@arkaria.postgresql.org; Thu, 14 Jul 2022 12:22:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oBxr9-0004Z7-DK for pgsql-jdbc@arkaria.postgresql.org; Thu, 14 Jul 2022 12:22:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oBxr9-0004Yn-4O for pgsql-jdbc@lists.postgresql.org; Thu, 14 Jul 2022 12:22:11 +0000 Received: from out-18.smtp.github.com ([192.30.252.201] helo=smtp.github.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oBxr6-0000bo-NY for pgsql-jdbc@lists.postgresql.org; Thu, 14 Jul 2022 12:22:10 +0000 Received: from github.com (hubbernetes-node-e566669.va3-iad.github.net [10.48.205.77]) by smtp.github.com (Postfix) with ESMTPA id AD4033408D0 for ; Thu, 14 Jul 2022 05:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=github.com; s=pf2014; t=1657801327; bh=BE8qi1SU5+cLquJM8k8tr3373J3oQoMflspWAGFtLd4=; h=Date:From:To:Subject:From; b=P/UEHjMCW97V5476uDRXbuw6OhfCofA7Tv2FUp8fuijzATFpDT7wfEzVXby+8sGN9 5o9QanPQa1NpuUyUyUuTAd5JlcVltHYB6U1x9uWZb4avyf4i2vwLiK1jwcXKjOuFaQ vgmAe1hrV6iND3fyRopjNws0AVYMu6ixZQ6CDv7w= Date: Thu, 14 Jul 2022 05:22:07 -0700 From: Daisuke To: pgsql-jdbc@lists.postgresql.org Message-ID: Subject: [pgjdbc/pgjdbc] 6e453a: test: fix ConnectTimeoutTest to hadle SocketTimeou... Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Approved: 58GruLoMopuc X-GitHub-Recipient-Address: pgsql-jdbc@lists.postgresql.org X-Auto-Response-Suppress: All List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Branch: refs/heads/master Home: https://github.com/pgjdbc/pgjdbc Commit: 6e453aaead9dc15bf648cb490e6bbef6a1a2c3a7 https://github.com/pgjdbc/pgjdbc/commit/6e453aaead9dc15bf648cb490e6bbef6a1a2c3a7 Author: Daisuke 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.