Skip to content

Commit beae6e8

Browse files
committed
Avoid static initialization deadlock in run tests
See #624 (comment) for a lengthy explanation.
1 parent dd80fe0 commit beae6e8

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

tests/run/t5375.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
object Test extends dotty.runtime.LegacyApp {
1+
object Test {
22
val foos = (1 to 1000).toSeq
3-
try
4-
foos.par.map(i => if (i % 37 == 0) sys.error("i div 37") else i)
5-
catch {
6-
case ex: RuntimeException => println("Runtime exception")
3+
4+
def main(args: Array[String]): Unit = {
5+
try
6+
foos.par.map(i => if (i % 37 == 0) sys.error("i div 37") else i)
7+
catch {
8+
case ex: RuntimeException => println("Runtime exception")
9+
}
710
}
811
}

tests/run/t6052.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77

8-
object Test extends dotty.runtime.LegacyApp {
8+
object Test {
99
def seqarr(i: Int) = Array[Int]() ++ (0 until i)
1010
def pararr(i: Int) = seqarr(i).par
1111

@@ -15,7 +15,9 @@ object Test extends dotty.runtime.LegacyApp {
1515
assert(gseq == gpar, (gseq, gpar))
1616
}
1717

18-
for (i <- 0 until 20) check(i, _ > 0)
19-
for (i <- 0 until 20) check(i, _ % 2)
20-
for (i <- 0 until 20) check(i, _ % 4)
18+
def main(args: Array[String]): Unit = {
19+
for (i <- 0 until 20) check(i, _ > 0)
20+
for (i <- 0 until 20) check(i, _ % 2)
21+
for (i <- 0 until 20) check(i, _ % 4)
22+
}
2123
}

tests/run/t6410.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11

22

33

4-
object Test extends dotty.runtime.LegacyApp {
5-
val x = collection.parallel.mutable.ParArray.range(1,10) groupBy { _ % 2 } mapValues { _.size }
6-
println(x)
7-
val y = collection.parallel.immutable.ParVector.range(1,10) groupBy { _ % 2 } mapValues { _.size }
8-
println(y)
4+
object Test {
5+
def main(args: Array[String]): Unit = {
6+
val x = collection.parallel.mutable.ParArray.range(1,10) groupBy { _ % 2 } mapValues { _.size }
7+
println(x)
8+
val y = collection.parallel.immutable.ParVector.range(1,10) groupBy { _ % 2 } mapValues { _.size }
9+
println(y)
10+
}
911
}

tests/run/t6467.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ import collection._
66

77

88

9-
object Test extends dotty.runtime.LegacyApp {
9+
object Test {
1010

1111
def compare(s1: String, s2: String): Unit = {
1212
assert(s1 == s2, s1 + "\nvs.\n" + s2)
1313
}
1414

15-
compare(List(1, 2, 3, 4).aggregate(new java.lang.StringBuffer)(_ append _, _ append _).toString, "1234")
16-
compare(List(1, 2, 3, 4).par.aggregate(new java.lang.StringBuffer)(_ append _, _ append _).toString, "1234")
17-
compare(Seq(0 until 100: _*).aggregate(new java.lang.StringBuffer)(_ append _, _ append _).toString, (0 until 100).mkString)
18-
compare(Seq(0 until 100: _*).par.aggregate(new java.lang.StringBuffer)(_ append _, _ append _).toString, (0 until 100).mkString)
15+
def main(args: Array[String]): Unit = {
16+
compare(List(1, 2, 3, 4).aggregate(new java.lang.StringBuffer)(_ append _, _ append _).toString, "1234")
17+
compare(List(1, 2, 3, 4).par.aggregate(new java.lang.StringBuffer)(_ append _, _ append _).toString, "1234")
18+
compare(Seq(0 until 100: _*).aggregate(new java.lang.StringBuffer)(_ append _, _ append _).toString, (0 until 100).mkString)
19+
compare(Seq(0 until 100: _*).par.aggregate(new java.lang.StringBuffer)(_ append _, _ append _).toString, (0 until 100).mkString)
20+
}
1921

2022
}

tests/run/t7498.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55

66

77

8-
object Test extends dotty.runtime.LegacyApp {
8+
object Test {
99
import scala.collection.concurrent.TrieMap
1010

1111
class Collision(val idx: Int) {
1212
override def hashCode = idx % 10
1313
}
1414

15-
val tm = TrieMap[Collision, Unit]()
16-
for (i <- 0 until 1000) tm(new Collision(i)) = ()
15+
def main(args: Array[String]): Unit = {
16+
val tm = TrieMap[Collision, Unit]()
17+
for (i <- 0 until 1000) tm(new Collision(i)) = ()
1718

18-
tm.par.foreach(kv => ())
19+
tm.par.foreach(kv => ())
20+
}
1921
}
2022

0 commit comments

Comments
 (0)