Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Fix EXIT chunk being sent twice #174

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}