File tree Expand file tree Collapse file tree
core/src/test/scala/com.codacy.analysis.core/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,19 +6,16 @@ class SetOpsSpec extends Specification {
66
77 " SetOps.mapInParallel" should {
88 " actually run in parallel" in {
9- val sleepMillis = 100L
10- val parallelism = 20
9+ val parallelism = 10
1110
12- val initialTime = System .currentTimeMillis()
13- SetOps .mapInParallel(1 .to(parallelism).toSet, Some (parallelism)) { _ =>
14- Thread .sleep(sleepMillis)
15- }
16- val finalTime = System .currentTimeMillis()
11+ val threadsIds = SetOps .mapInParallel(1 .to(parallelism).toSet, Some (parallelism)) { _ =>
12+ // If the function terminates too fast the thread pool reuses the same threads
13+ Thread .sleep(100 )
1714
18- val elapsedMillis = finalTime - initialTime
19- val expectedMaxMillis = (sleepMillis * parallelism * 0.95 ).toLong
15+ Thread .currentThread().getId()
16+ }
2017
21- elapsedMillis should beLessThan(expectedMaxMillis )
18+ threadsIds.distinct should haveSize(parallelism )
2219 }
2320 }
2421}
You can’t perform that action at this time.
0 commit comments