Skip to content
Merged
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
2 changes: 2 additions & 0 deletions java/sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
<workingDirectory>${copilot.sdk.root}/test/harness</workingDirectory>
<arguments>
<argument>ci</argument>
<argument>--omit-lockfile-registry-resolved=true</argument>
Comment thread
edburns marked this conversation as resolved.
<argument>--loglevel</argument>
<argument>${npm.loglevel}</argument>
</arguments>
Expand All @@ -225,6 +226,7 @@
<arguments>
<argument>ci</argument>
<argument>--ignore-scripts</argument>
<argument>--omit-lockfile-registry-resolved=true</argument>
<argument>--loglevel</argument>
<argument>${npm.loglevel}</argument>
</arguments>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,13 @@ void connectToServerTcpMode() throws Exception {
}
}

private static Process startBlockingProcess() throws IOException {
boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
return (isWindows
? new ProcessBuilder(System.getenv("COMSPEC"), "/c", "more")
: new ProcessBuilder("/usr/bin/cat")).start();
}

@Test
void connectToServerStdioMode() throws Exception {
var options = new CopilotClientOptions();
var manager = new CliServerManager(options);

// Create a dummy process for stdio mode
Process process = startBlockingProcess();
Process process = new TestProcess();
try {
JsonRpcClient client = manager.connectToServer(process, null, null);
assertNotNull(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,17 @@ void testIsConnectedWithSocketClosed() throws Exception {
pair.serverSocket.close();
}

private static Process startBlockingProcess() throws IOException {
boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
return (isWindows
? new ProcessBuilder(System.getenv("COMSPEC"), "/c", "more")
: new ProcessBuilder("/usr/bin/cat")).start();
}

@Test
void testIsConnectedWithProcess() throws Exception {
Process proc = startBlockingProcess();
Process proc = new TestProcess();
try (var client = JsonRpcClient.fromProcess(proc)) {
assertTrue(client.isConnected());
}
}

@Test
void testIsConnectedWithProcessDead() throws Exception {
Process proc = startBlockingProcess();
Process proc = new TestProcess();
var client = JsonRpcClient.fromProcess(proc);
proc.destroy();
proc.waitFor(5, TimeUnit.SECONDS);
Expand All @@ -162,7 +155,7 @@ void testIsConnectedWithProcessDead() throws Exception {

@Test
void testGetProcessReturnsProcess() throws Exception {
Process proc = startBlockingProcess();
Process proc = new TestProcess();
try (var client = JsonRpcClient.fromProcess(proc)) {
assertSame(proc, client.getProcess());
}
Expand Down
65 changes: 65 additions & 0 deletions java/sdk/src/test/java/com/github/copilot/TestProcess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/

package com.github.copilot;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

final class TestProcess extends Process {

private final CountDownLatch terminated = new CountDownLatch(1);

@Override
public OutputStream getOutputStream() {
return OutputStream.nullOutputStream();
}

@Override
public InputStream getInputStream() {
return InputStream.nullInputStream();
}

@Override
public InputStream getErrorStream() {
return InputStream.nullInputStream();
}

@Override
public int waitFor() throws InterruptedException {
terminated.await();
return 0;
}

@Override
public boolean waitFor(long timeout, TimeUnit unit) throws InterruptedException {
return terminated.await(timeout, unit);
}

@Override
public int exitValue() {
if (isAlive()) {
throw new IllegalThreadStateException("Process has not exited");
}
return 0;
}

@Override
public void destroy() {
terminated.countDown();
}

@Override
public Process destroyForcibly() {
destroy();
return this;
}

@Override
public boolean isAlive() {
return terminated.getCount() > 0;
}
}
Loading