|
5 | 5 | package org.mozilla.javascript.tests;
|
6 | 6 |
|
7 | 7 | import static org.junit.Assert.assertEquals;
|
| 8 | +import static org.junit.Assert.assertThrows; |
| 9 | +import static org.junit.Assert.assertTrue; |
8 | 10 |
|
9 | 11 | import org.junit.Test;
|
10 | 12 | import org.mozilla.javascript.Context;
|
11 | 13 | import org.mozilla.javascript.Scriptable;
|
12 | 14 | import org.mozilla.javascript.ScriptableObject;
|
13 | 15 |
|
| 16 | +import java.util.concurrent.ExecutionException; |
| 17 | +import java.util.concurrent.ExecutorService; |
| 18 | +import java.util.concurrent.Executors; |
| 19 | +import java.util.concurrent.Future; |
| 20 | +import java.util.concurrent.TimeUnit; |
| 21 | +import java.util.concurrent.TimeoutException; |
| 22 | + |
14 | 23 | public class NativeRegExpTest {
|
15 | 24 |
|
16 | 25 | @Test
|
@@ -49,6 +58,21 @@ public void ignoreCase() throws Exception {
|
49 | 58 | testEvaluate("i-false-true-false-false", "/foo/i;");
|
50 | 59 | }
|
51 | 60 |
|
| 61 | + /** @throws Exception if an error occurs */ |
| 62 | + @Test |
| 63 | + public void interruptLongRunningRegExpEvaluation() throws Exception { |
| 64 | + ExecutorService executorService = Executors.newSingleThreadExecutor(); |
| 65 | + try { |
| 66 | + Future<?> future = executorService.submit(() -> test("false", "/(.*){1,32000}[bc]/.test(\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\");")); |
| 67 | + assertThrows(TimeoutException.class, () -> future.get(1, TimeUnit.SECONDS)); |
| 68 | + executorService.shutdownNow(); |
| 69 | + assertTrue(executorService.awaitTermination(30, TimeUnit.SECONDS)); |
| 70 | + } |
| 71 | + finally { |
| 72 | + executorService.shutdown(); |
| 73 | + } |
| 74 | + } |
| 75 | + |
52 | 76 | /** @throws Exception if an error occurs */
|
53 | 77 | @Test
|
54 | 78 | public void multilineCtor() throws Exception {
|
|
0 commit comments