bring back test

This commit is contained in:
marc hurabielle 2019-03-22 12:31:13 +09:00
parent d43f03da9e
commit bc2b4f6e66

View file

@ -286,6 +286,49 @@ public class IPythonInterpreterTest extends BasePythonInterpreterTest {
context.out.toInterpreterResultMessage().get(1).getType());
}
@Test
public void testIpython_shouldNotHang_whenCallingAutoCompleteAndInterpretConcurrently()
throws InterpreterException,
InterruptedException, TimeoutException, ExecutionException {
tearDown();
Properties properties = initIntpProperties();
startInterpreter(properties);
final String code = "import time\n"
+ "print(1)\n"
+ "time.sleep(10)\n"
+ "print(2)";
final String base = "time.";
// The goal of this test is to ensure that concurrent interpret and complete
// will not make execute hang forever.
ExecutorService pool = Executors.newFixedThreadPool(2);
FutureTask<InterpreterResult> interpretFuture =
new FutureTask(new Callable() {
@Override
public Object call() throws Exception {
return interpreter.interpret(code, getInterpreterContext());
}
});
FutureTask<List<InterpreterCompletion>> completionFuture =
new FutureTask(new Callable() {
@Override
public Object call() throws Exception {
return interpreter.completion(base, base.length(), null);
}
});
pool.execute(interpretFuture);
// we sleep to ensure that the paragraph is running
Thread.sleep(3000);
pool.execute(completionFuture);
// We ensure that running and auto completion are not hanging.
InterpreterResult res = interpretFuture.get(20000, TimeUnit.MILLISECONDS);
List<InterpreterCompletion> autoRes = completionFuture.get(1000, TimeUnit.MILLISECONDS);
assertTrue(res.code().name().equals("SUCCESS"));
assertTrue(autoRes.size() > 0);
}
@Test
public void testGrpcFrameSize() throws InterpreterException, IOException {
tearDown();