-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test parallelism in EnsoParser. Using
synchronized
to avoid it. (#1…
…1174) * Stress test to verify how EnsoParser behaves under multi threaded load * Avoid concurrency in native code by synchronizing parser methods
- Loading branch information
1 parent
a63a616
commit 7269cdf
Showing
2 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
engine/runtime-parser/src/test/java/org/enso/compiler/core/EnsoParserMultiThreadedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.enso.compiler.core; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ForkJoinPool; | ||
import org.enso.compiler.core.ir.Module; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class EnsoParserMultiThreadedTest { | ||
private EnsoParser parser; | ||
|
||
@Before | ||
public void initParser() throws Exception { | ||
parser = new EnsoParser(); | ||
} | ||
|
||
@After | ||
public void closeParser() throws Exception { | ||
parser.close(); | ||
} | ||
|
||
@Test | ||
public void stressLoadFromManyThreads() throws Exception { | ||
List<Callable<Module>> cases = new ArrayList<>(); | ||
final var testCases = 1000; | ||
for (var i = 0; i < 2 * testCases; i++) { | ||
var number = i % testCases; | ||
var code = | ||
""" | ||
from Standard.Base import all | ||
main = %n | ||
""" | ||
.replace("%n", "" + number); | ||
cases.add( | ||
() -> { | ||
return parser.compile(code); | ||
}); | ||
} | ||
|
||
var results = ForkJoinPool.commonPool().invokeAll(cases); | ||
|
||
for (var i = 0; i < testCases; i++) { | ||
var r1 = results.get(i).get(); | ||
var r2 = results.get(testCases + i).get(); | ||
|
||
EnsoParserTest.assertIR("Run #" + i + " should produce identical IR", r1, r2); | ||
} | ||
} | ||
} |