Skip to content

Commit 30ff594

Browse files
committed
Close engines instead of letting them leak
1 parent 9fdb888 commit 30ff594

File tree

12 files changed

+37
-14
lines changed

12 files changed

+37
-14
lines changed

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/EngineOptionsTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void engineOptions() {
5858
assertEquals("java", doit(engine, null));
5959
assertEquals("java", doit(engine, "java"));
6060
assertEquals("native", doit(engine, "native"));
61+
engine.close();
6162
}
6263

6364
private static String doit(Engine engine, String backend) {

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/advanced/MultiContextTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public void testSharingWithMemoryview() {
5555
context.eval("python", "memoryview(b'abc')");
5656
}
5757
}
58+
engine.close();
5859
}
5960

6061
@Test
@@ -72,6 +73,7 @@ public void testTryCatch() {
7273
"last_val");
7374
}
7475
}
76+
engine.close();
7577
}
7678

7779
private static Context newContext(Engine engine) {

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/advanced/NativeExtTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public void testSharingErrorWithCpythonSre() throws InterruptedException {
104104

105105
} finally {
106106
cextContext.close(true);
107+
engine.close();
107108
}
108109
}
109110

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/advanced/ResourcesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void testResourcesAsHome() {
7373

7474
@Test
7575
public void testResourcesAlwaysAllowReading() {
76-
try (Context context = Context.newBuilder("python").engine(Engine.create("python")).allowIO(IOAccess.NONE).option("python.PythonHome", "/path/that/does/not/exist").build()) {
76+
try (Engine engine = Engine.create("python"); Context context = Context.newBuilder("python").engine(engine).allowIO(IOAccess.NONE).option("python.PythonHome", "/path/that/does/not/exist").build()) {
7777
String foundHome = context.eval("python", "import email; email.__spec__.origin").asString();
7878
assertTrue(foundHome, foundHome.contains("python" + File.separator + "python-home"));
7979
}

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/interop/ArgumentsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public void setUpTest() {
8181
@After
8282
public void tearDown() {
8383
context.close();
84+
context.getEngine().close();
8485
}
8586

8687
public interface TestPositionalArgsLong {

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/interop/JavaInteropTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public void setUpTest() {
104104
@After
105105
public void tearDown() {
106106
context.close();
107+
context.getEngine().close();
107108
}
108109

109110
@Test
@@ -119,7 +120,7 @@ public void evalFailsOnError() {
119120

120121
@Test
121122
public void evalNonInteractiveThrowsSyntaxError() throws IOException {
122-
try (Context c = Context.newBuilder().engine(Engine.create("python")).allowExperimentalOptions(true).allowAllAccess(true).option("python.TerminalIsInteractive", "false").build()) {
123+
try (Engine engine = Engine.create("python"); Context c = Context.newBuilder().engine(engine).allowExperimentalOptions(true).allowAllAccess(true).option("python.TerminalIsInteractive", "false").build()) {
123124
c.eval(Source.newBuilder("python", INCOMPLETE_SOURCE, "eval").interactive(false).build());
124125
} catch (PolyglotException t) {
125126
assertTrue(t.isSyntaxError());
@@ -131,7 +132,7 @@ public void evalNonInteractiveThrowsSyntaxError() throws IOException {
131132

132133
@Test
133134
public void evalNonInteractiveInInteractiveTerminalThrowsSyntaxError() throws IOException {
134-
try (Context c = Context.newBuilder().engine(Engine.create("python")).allowExperimentalOptions(true).allowAllAccess(true).option("python.TerminalIsInteractive", "true").build()) {
135+
try (Engine engine = Engine.create("python"); Context c = Context.newBuilder().engine(engine).allowExperimentalOptions(true).allowAllAccess(true).option("python.TerminalIsInteractive", "true").build()) {
135136
c.eval(Source.newBuilder("python", INCOMPLETE_SOURCE, "eval").interactive(false).build());
136137
} catch (PolyglotException t) {
137138
assertTrue(t.isSyntaxError());
@@ -143,7 +144,7 @@ public void evalNonInteractiveInInteractiveTerminalThrowsSyntaxError() throws IO
143144

144145
@Test
145146
public void evalInteractiveInNonInteractiveTerminalThrowsSyntaxError() throws IOException {
146-
try (Context c = Context.newBuilder().engine(Engine.create("python")).allowExperimentalOptions(true).allowAllAccess(true).option("python.TerminalIsInteractive", "false").build()) {
147+
try (Engine engine = Engine.create("python"); Context c = Context.newBuilder().engine(engine).allowExperimentalOptions(true).allowAllAccess(true).option("python.TerminalIsInteractive", "false").build()) {
147148
c.eval(Source.newBuilder("python", INCOMPLETE_SOURCE, "eval").interactive(true).build());
148149
} catch (PolyglotException t) {
149150
assertTrue(t.isSyntaxError());
@@ -155,7 +156,7 @@ public void evalInteractiveInNonInteractiveTerminalThrowsSyntaxError() throws IO
155156

156157
@Test
157158
public void evalInteractiveInInteractiveTerminalThrowsSyntaxError() throws IOException {
158-
try (Context c = Context.newBuilder().engine(Engine.create("python")).allowExperimentalOptions(true).allowAllAccess(true).option("python.TerminalIsInteractive", "true").build()) {
159+
try (Engine engine = Engine.create("python"); Context c = Context.newBuilder().engine(engine).allowExperimentalOptions(true).allowAllAccess(true).option("python.TerminalIsInteractive", "true").build()) {
159160
c.eval(Source.newBuilder("python", INCOMPLETE_SOURCE, "eval").interactive(true).build());
160161
} catch (PolyglotException t) {
161162
assertTrue(t.isSyntaxError());
@@ -168,7 +169,7 @@ public void evalInteractiveInInteractiveTerminalThrowsSyntaxError() throws IOExc
168169

169170
@Test
170171
public void importingJavaLangStringConvertsEagerly() {
171-
try (Context c = Context.newBuilder().engine(Engine.create("python")).allowExperimentalOptions(true).allowAllAccess(true).build()) {
172+
try (Engine engine = Engine.create("python"); Context c = Context.newBuilder().engine(engine).allowExperimentalOptions(true).allowAllAccess(true).build()) {
172173
c.getPolyglotBindings().putMember("b", "hello world");
173174
c.eval("python", "import polyglot; xyz = polyglot.import_value('b'); assert isinstance(xyz, str)");
174175
// should not fail
@@ -177,7 +178,7 @@ public void importingJavaLangStringConvertsEagerly() {
177178

178179
@Test
179180
public void evalWithSyntaxErrorThrows() {
180-
try (Context c = Context.newBuilder().engine(Engine.create("python")).build()) {
181+
try (Engine engine = Engine.create("python"); Context c = Context.newBuilder().engine(engine).build()) {
181182
c.eval("python", "var d=5/0");
182183
} catch (PolyglotException t) {
183184
assertTrue(t.isSyntaxError());

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/interop/TimeDateTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public void setUpTest() {
8282
@After
8383
public void tearDown() {
8484
context.close();
85+
context.getEngine().close();
8586
}
8687

8788
@Test

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/module/LocaleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void localeconvWithJvmLocale() {
8282
@Test
8383
public void getlocaleWithOption() {
8484
String expectedEncoding = Charset.defaultCharset().displayName();
85-
try (Context context = Context.newBuilder("python").engine(Engine.create("python")).option("python.InitialLocale", "en_GB").build()) {
85+
try (Engine engine = Engine.create("python"); Context context = Context.newBuilder("python").engine(engine).option("python.InitialLocale", "en_GB").build()) {
8686
Value tuple = context.eval("python", "import locale; locale.getlocale()");
8787
assertEquals("en_GB", tuple.getArrayElement(0).asString());
8888
assertEquals(expectedEncoding, tuple.getArrayElement(1).asString());

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/module/LzmaTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static boolean[] params() {
6161

6262
@Test
6363
public void testLzmaBasics() {
64-
try (Context context = Context.newBuilder("python").engine(Engine.create("python")).allowNativeAccess(useNative).build()) {
64+
try (Engine engine = Engine.create("python"); Context context = Context.newBuilder("python").engine(engine).allowNativeAccess(useNative).build()) {
6565
Value isSupported = context.eval("python", "import lzma; lzma.is_check_supported(lzma.CHECK_CRC32)");
6666
assertTrue(isSupported.isBoolean());
6767
assertTrue(isSupported.asBoolean());

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/module/MemoryviewTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@
4949
public class MemoryviewTest extends PythonTests {
5050
@Test
5151
public void testContextReuse() {
52-
Engine engine = Engine.create("python");
53-
try (Context context = newContext(engine)) {
54-
context.eval("python", "memoryview(b'abc')");
52+
try (Engine engine = Engine.create("python")) {
53+
try (Context context = newContext(engine)) {
54+
context.eval("python", "memoryview(b'abc')");
55+
}
5556
}
5657
}
5758

0 commit comments

Comments
 (0)