Skip to content

Commit 6b3cc5f

Browse files
committed
Simplify largeMessage test
Further, reduce some code duplication.
1 parent 052901f commit 6b3cc5f

File tree

1 file changed

+11
-42
lines changed

1 file changed

+11
-42
lines changed

js-envs-test-kit/src/main/scala/org/scalajs/jsenv/test/ComTests.scala

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -79,57 +79,26 @@ private[test] class ComTests(config: JSEnvSuiteConfig) {
7979
}
8080
}
8181

82-
@Test
83-
def largeMessageTest: Unit = {
84-
// 1KB data
85-
val baseMsg = new String(Array.tabulate(512)(_.toChar))
86-
val baseLen = baseMsg.length
87-
88-
// Max message size: 1KB * 2^(2*iters+1) = 1MB
89-
val iters = 4
90-
91-
val run = kit.start("""
92-
scalajsCom.init(function(msg) {
93-
scalajsCom.send(msg + msg);
94-
});
95-
""", RunConfig())
82+
private def replyTest(msg: String) = {
83+
val run = kit.start("scalajsCom.init(scalajsCom.send);", RunConfig())
9684

9785
try {
98-
run.run.send(baseMsg)
99-
100-
def resultFactor(iters: Int) = Math.pow(2, 2 * iters + 1).toInt
101-
102-
for (i <- 0 until iters) {
103-
val reply = run.waitNextMessage()
104-
105-
val factor = resultFactor(i)
106-
107-
assertEquals(baseLen * factor, reply.length)
108-
109-
for (j <- 0 until factor)
110-
assertEquals(baseMsg, reply.substring(j * baseLen, (j + 1) * baseLen))
111-
112-
run.run.send(reply + reply)
113-
}
114-
115-
val lastLen = run.waitNextMessage().length
116-
assertEquals(baseLen * resultFactor(iters), lastLen)
86+
run.run.send(msg)
87+
assertEquals(msg, run.waitNextMessage())
11788
} finally {
11889
run.closeAndWait()
11990
}
12091
}
12192

12293
@Test
123-
def highCharTest: Unit = { // #1536
124-
val run = kit.start("scalajsCom.init(scalajsCom.send);", RunConfig())
94+
def largeMessageTest: Unit = {
95+
// 1MB data
96+
replyTest(new String(Array.tabulate(1024 * 1024)(_.toChar)))
97+
}
12598

126-
try {
127-
val msg = "\uC421\u8F10\u0112\uFF32"
128-
run.run.send(msg)
129-
assertEquals(msg, run.waitNextMessage())
130-
} finally {
131-
run.closeAndWait()
132-
}
99+
@Test
100+
def highCharTest: Unit = { // #1536
101+
replyTest("\uC421\u8F10\u0112\uFF32")
133102
}
134103

135104
@Test

0 commit comments

Comments
 (0)