UploadPackTest: ensure UploadPack is closed to fix resource leak

Change-Id: I4c8cf6041b4011934d338138d4531d190fdd6abb
This commit is contained in:
Matthias Sohn 2022-11-20 21:24:00 +01:00
parent 4ddc64a2dd
commit bde09c185f
1 changed files with 43 additions and 37 deletions

View File

@ -2416,35 +2416,39 @@ public void testGetPeerAgentProtocolV0() throws Exception {
RevCommit one = remote.commit().message("1").create();
remote.update("one", one);
UploadPack up = new UploadPack(server);
try (UploadPack up = new UploadPack(server)) {
ByteArrayInputStream send = linesAsInputStream(
"want " + one.getName() + " agent=JGit-test/1.2.3\n",
PacketLineIn.end(),
"have 11cedf1b796d44207da702f7d420684022fc0f09\n", "done\n");
"have 11cedf1b796d44207da702f7d420684022fc0f09\n",
"done\n");
ByteArrayOutputStream recv = new ByteArrayOutputStream();
up.upload(send, recv, null);
assertEquals(up.getPeerUserAgent(), "JGit-test/1.2.3");
}
}
@Test
public void testGetSessionIDValueProtocolV0() throws Exception {
RevCommit one = remote.commit().message("1").create();
remote.update("one", one);
UploadPack up = new UploadPack(server);
try (UploadPack up = new UploadPack(server)) {
ByteArrayInputStream send = linesAsInputStream(
"want " + one.getName() + " agent=JGit-test/1.2.3"
+ " session-id=client-session-id\n",
PacketLineIn.end(),
"have 11cedf1b796d44207da702f7d420684022fc0f09\n", "done\n");
"have 11cedf1b796d44207da702f7d420684022fc0f09\n",
"done\n");
ByteArrayOutputStream recv = new ByteArrayOutputStream();
up.upload(send, recv, null);
assertEquals(up.getClientSID(), "client-session-id");
}
}
@Test
public void testGetPeerAgentProtocolV2() throws Exception {
@ -2455,12 +2459,12 @@ public void testGetPeerAgentProtocolV2() throws Exception {
RevCommit one = remote.commit().message("1").create();
remote.update("one", one);
UploadPack up = new UploadPack(server);
try (UploadPack up = new UploadPack(server)) {
up.setExtraParameters(Sets.of("version=2"));
ByteArrayInputStream send = linesAsInputStream(
"command=fetch\n", "agent=JGit-test/1.2.4\n",
PacketLineIn.delimiter(), "want " + one.getName() + "\n",
ByteArrayInputStream send = linesAsInputStream("command=fetch\n",
"agent=JGit-test/1.2.4\n", PacketLineIn.delimiter(),
"want " + one.getName() + "\n",
"have 11cedf1b796d44207da702f7d420684022fc0f09\n", "done\n",
PacketLineIn.end());
@ -2469,6 +2473,7 @@ public void testGetPeerAgentProtocolV2() throws Exception {
assertEquals(up.getPeerUserAgent(), "JGit-test/1.2.4");
}
}
@Test
public void testGetSessionIDValueProtocolV2() throws Exception {
@ -2479,7 +2484,7 @@ public void testGetSessionIDValueProtocolV2() throws Exception {
RevCommit one = remote.commit().message("1").create();
remote.update("one", one);
UploadPack up = new UploadPack(server);
try (UploadPack up = new UploadPack(server)) {
up.setExtraParameters(Sets.of("version=2"));
ByteArrayInputStream send = linesAsInputStream("command=fetch\n",
@ -2493,6 +2498,7 @@ public void testGetSessionIDValueProtocolV2() throws Exception {
assertEquals(up.getClientSID(), "client-session-id");
}
}
private static class RejectAllRefFilter implements RefFilter {
@Override