From 6c62904b3c8b85deedceff03f3c7558356f3e62f Mon Sep 17 00:00:00 2001 From: Hal Blackburn Date: Tue, 13 Aug 2019 13:08:02 +0100 Subject: [PATCH] Fix EXIT chunk being sent twice The server was sending the expected EXIT chunk, followed by an EXIT chunk containing a newline character. --- .../java/com/facebook/nailgun/NGCommunicator.java | 2 +- .../com/facebook/nailgun/NGCommunicatorTest.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/nailgun-server/src/main/java/com/facebook/nailgun/NGCommunicator.java b/nailgun-server/src/main/java/com/facebook/nailgun/NGCommunicator.java index 8038a1c3..55c1a427 100644 --- a/nailgun-server/src/main/java/com/facebook/nailgun/NGCommunicator.java +++ b/nailgun-server/src/main/java/com/facebook/nailgun/NGCommunicator.java @@ -338,7 +338,7 @@ void exit(int exitCode) { // send the command - client will exit try (PrintStream exit = new PrintStream(new NGOutputStream(this, NGConstants.CHUNKTYPE_EXIT))) { - exit.println(exitCode); + exit.print(exitCode); } isExited = true; diff --git a/nailgun-server/src/test/java/com/facebook/nailgun/NGCommunicatorTest.java b/nailgun-server/src/test/java/com/facebook/nailgun/NGCommunicatorTest.java index ad021c8f..59a98a23 100644 --- a/nailgun-server/src/test/java/com/facebook/nailgun/NGCommunicatorTest.java +++ b/nailgun-server/src/test/java/com/facebook/nailgun/NGCommunicatorTest.java @@ -18,6 +18,7 @@ package com.facebook.nailgun; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.mock; @@ -89,4 +90,15 @@ void canWriteData() throws IOException { verify(ostream).write(data, 0, data.length); } + + @Test + void canSendExitCode() throws IOException { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + when(socket.getOutputStream()).thenReturn(output); + + NGCommunicator comm = new NGCommunicator(socket, 0); + comm.exit(42); + + assertArrayEquals(new byte[] {0x00, 0x00, 0x00, 0x02, 'X', '4', '2'}, output.toByteArray()); + } }