Skip to content

Commit 48aa95a

Browse files
Apply review comments
1 parent e93d998 commit 48aa95a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/test/java/com/microsoft/sqlserver/jdbc/connection/TimeoutTest.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,21 @@ public void testDMLoginTimeoutApplied() {
9393
public void testDMLoginTimeoutNotApplied() {
9494
long timerEnd = 0;
9595
int timeout = 10;
96+
try {
97+
DriverManager.setLoginTimeout(timeout * 3); // 30 seconds
98+
long timerStart = System.currentTimeMillis();
9699

97-
DriverManager.setLoginTimeout(timeout * 3); // 30 seconds
98-
long timerStart = System.currentTimeMillis();
99-
100-
try (Connection con = PrepUtil
101-
.getConnection("jdbc:sqlserver://" + randomServer + ";user=sa;password=pwd;loginTimeout=" + timeout)) {
102-
fail(TestResource.getResource("R_shouldNotConnect"));
103-
} catch (Exception e) {
104-
assertTrue(e.getMessage().contains(TestResource.getResource("R_tcpipConnectionToHost")));
105-
timerEnd = System.currentTimeMillis();
100+
try (Connection con = PrepUtil.getConnection(
101+
"jdbc:sqlserver://" + randomServer + ";user=sa;password=pwd;loginTimeout=" + timeout)) {
102+
fail(TestResource.getResource("R_shouldNotConnect"));
103+
} catch (Exception e) {
104+
assertTrue(e.getMessage().contains(TestResource.getResource("R_tcpipConnectionToHost")));
105+
timerEnd = System.currentTimeMillis();
106+
}
107+
verifyTimeout(timerEnd - timerStart, timeout);
108+
} finally {
109+
DriverManager.setLoginTimeout(0); // Default to 0 again
106110
}
107-
108-
verifyTimeout(timerEnd - timerStart, timeout);
109-
110-
DriverManager.setLoginTimeout(0); // Default to 0 again
111111
}
112112

113113
@Test

0 commit comments

Comments
 (0)