Skip to content

Commit e4ed7ce

Browse files
committedApr 26, 2024
8331063: Some HttpClient tests don't report leaks
Reviewed-by: dfuchs, vtewari, michaelm
1 parent cfd19f0 commit e4ed7ce

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed
 

‎test/jdk/java/net/httpclient/ForbiddenHeadTest.java

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -205,18 +205,18 @@ static final void printFailedTests(ITestContext context) {
205205
@DataProvider(name = "all")
206206
public Object[][] allcases() {
207207
List<Object[]> result = new ArrayList<>();
208-
for (var client : List.of(authClient, noAuthClient)) {
208+
for (boolean useAuth : List.of(true, false)) {
209209
for (boolean async : List.of(true, false)) {
210210
for (int code : List.of(UNAUTHORIZED, PROXY_UNAUTHORIZED)) {
211211
var srv = code == PROXY_UNAUTHORIZED ? "/proxy" : "/server";
212212
for (var auth : List.of("/auth", "/noauth")) {
213213
var pcode = code;
214214
if (auth.equals("/noauth")) {
215-
if (client == authClient) continue;
215+
if (useAuth) continue;
216216
pcode = FORBIDDEN;
217217
}
218218
for (var uri : List.of(httpURI, httpsURI, http2URI, https2URI)) {
219-
result.add(new Object[]{uri + srv + auth, pcode, async, client});
219+
result.add(new Object[]{uri + srv + auth, pcode, async, useAuth});
220220
}
221221
}
222222
}
@@ -237,12 +237,13 @@ protected PasswordAuthentication getPasswordAuthentication() {
237237
static final AtomicLong sleepCount = new AtomicLong();
238238

239239
@Test(dataProvider = "all")
240-
void test(String uriString, int code, boolean async, HttpClient client) throws Throwable {
240+
void test(String uriString, int code, boolean async, boolean useAuth) throws Throwable {
241241
checkSkip();
242+
HttpClient client = useAuth ? authClient : noAuthClient;
242243
var name = String.format("test(%s, %d, %s, %s)", uriString, code, async ? "async" : "sync",
243244
client.authenticator().isPresent() ? "authClient" : "noAuthClient");
244245
out.printf("%n---- starting %s ----%n", name);
245-
assert client.authenticator().isPresent() ? client == authClient : client == noAuthClient;
246+
assert client.authenticator().isPresent() == useAuth;
246247
uriString = uriString + "/ForbiddenTest";
247248
for (int i=0; i<ITERATIONS; i++) {
248249
if (ITERATIONS > 1) out.printf("---- ITERATION %d%n",i);
@@ -381,13 +382,16 @@ public void teardown() throws Exception {
381382
authClient = noAuthClient = null;
382383
Thread.sleep(100);
383384
AssertionError fail = TRACKER.check(500);
384-
385-
proxy.stop();
386-
authproxy.stop();
387-
httpTestServer.stop();
388-
httpsTestServer.stop();
389-
http2TestServer.stop();
390-
https2TestServer.stop();
385+
try {
386+
proxy.stop();
387+
authproxy.stop();
388+
httpTestServer.stop();
389+
httpsTestServer.stop();
390+
http2TestServer.stop();
391+
https2TestServer.stop();
392+
} finally {
393+
if (fail != null) throw fail;
394+
}
391395
}
392396

393397
static class TestProxySelector extends ProxySelector {

‎test/jdk/java/net/httpclient/ProxySelectorTest.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -377,15 +377,18 @@ public void teardown() throws Exception {
377377
client = null;
378378
Thread.sleep(100);
379379
AssertionError fail = TRACKER.check(500);
380-
381-
proxy.stop();
382-
authproxy.stop();
383-
httpTestServer.stop();
384-
proxyHttpTestServer.stop();
385-
authProxyHttpTestServer.stop();
386-
httpsTestServer.stop();
387-
http2TestServer.stop();
388-
https2TestServer.stop();
380+
try {
381+
proxy.stop();
382+
authproxy.stop();
383+
httpTestServer.stop();
384+
proxyHttpTestServer.stop();
385+
authProxyHttpTestServer.stop();
386+
httpsTestServer.stop();
387+
http2TestServer.stop();
388+
https2TestServer.stop();
389+
} finally {
390+
if (fail != null) throw fail;
391+
}
389392
}
390393

391394
class TestProxySelector extends ProxySelector {

0 commit comments

Comments
 (0)
Please sign in to comment.