Skip to content

Commit 0bf25c0

Browse files
committed
Fix tests.
JAVA-5856
1 parent b8ac9f6 commit 0bf25c0

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

driver-core/src/main/com/mongodb/internal/TimeoutSettings.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ public TimeoutSettings withReadTimeoutMS(final long readTimeoutMS) {
165165
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
166166
}
167167

168+
public TimeoutSettings withConnectTimeoutMS(final long connectTimeoutMS) {
169+
return new TimeoutSettings(generationId, timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
170+
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);
171+
}
172+
168173
public TimeoutSettings withServerSelectionTimeoutMS(final long serverSelectionTimeoutMS) {
169174
return new TimeoutSettings(timeoutMS, serverSelectionTimeoutMS, connectTimeoutMS, readTimeoutMS, maxAwaitTimeMS,
170175
maxTimeMS, maxCommitTimeMS, wTimeoutMS, maxWaitTimeMS);

driver-core/src/test/functional/com/mongodb/internal/connection/TlsChannelStreamFunctionalTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,29 @@ void shouldInterruptConnectionEstablishmentWhenConnectionTimeoutExpires(final in
7575

7676
//then
7777
long elapsedMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - connectOpenStart);
78+
long diff = elapsedMs - connectTimeout;
79+
// Allowed difference, with test overhead setup is 300MS.
80+
int epsilonMs = 300;
81+
7882
assertInstanceOf(InterruptedByTimeoutException.class, mongoSocketOpenException.getCause(),
7983
"Actual cause: " + mongoSocketOpenException.getCause());
80-
long diff = elapsedMs - connectTimeout;
8184
assertFalse(diff < 0,
8285
String.format("Connection timed-out sooner than expected. Difference: %d ms", diff));
83-
// Allowed difference, with test overhead setup is 300MS.
84-
int epsilon = 300;
85-
assertTrue(diff < epsilon,
86-
String.format("Elapsed time %d ms should be within %d ms of the connect timeout", elapsedMs, epsilon));
86+
assertTrue(diff < epsilonMs,
87+
String.format("Elapsed time %d ms should be within %d ms of the connect timeout", elapsedMs, epsilonMs));
8788
}
8889
}
8990

9091
@ParameterizedTest
9192
@ValueSource(ints = {0, 500, 1000, 2000})
9293
void shouldEstablishConnection(final int connectTimeout) throws IOException {
94+
//given
9395
try (TlsChannelStreamFactoryFactory factory = new TlsChannelStreamFactoryFactory(new DefaultInetAddressResolver())) {
94-
//given
9596
StreamFactory streamFactory = factory.create(SocketSettings.builder()
9697
.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
9798
.build(), SSL_SETTINGS);
9899

99100
Stream stream = streamFactory.create(new ServerAddress("localhost", port));
100-
101101
try {
102102
//when
103103
stream.open(OperationContext.simpleOperationContext(

0 commit comments

Comments
 (0)