Skip to content

Commit d07fd61

Browse files
authored
Merge pull request #1327 from nevkontakte/quicker-tests
Make slow stdlib tests faster.
2 parents 33199c5 + 7f39243 commit d07fd61

File tree

10 files changed

+110
-30
lines changed

10 files changed

+110
-30
lines changed

compiler/natives/src/crypto/ed25519/ed25519vectors_test.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

compiler/natives/src/crypto/ed25519/internal/edwards25519/field/fe_test.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

compiler/natives/src/crypto/ed25519/internal/edwards25519/scalar_test.go

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build js
2+
3+
package field
4+
5+
import (
6+
"testing"
7+
"testing/quick"
8+
)
9+
10+
//gopherjs:keep-original
11+
func TestAliasing(t *testing.T) {
12+
// The test heavily uses 64-bit math, which is slow under GopherJS. Reducing
13+
// the number of iterations makes run time more manageable.
14+
t.Cleanup(quick.GopherJSInternalMaxCountCap(100))
15+
_gopherjs_original_TestAliasing(t)
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build js
2+
3+
package field
4+
5+
import "testing/quick"
6+
7+
// Tests in this package use 64-bit math, which is slow under GopherJS. To keep
8+
// test run time reasonable, we reduce the number of test iterations.
9+
var quickCheckConfig1024 = &quick.Config{MaxCountScale: 10}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build js
2+
3+
package edwards25519
4+
5+
import "testing/quick"
6+
7+
// Tests in this package use 64-bit math, which is slow under GopherJS. To keep
8+
// test run time reasonable, we reduce the number of test iterations.
9+
var quickCheckConfig1024 = &quick.Config{MaxCountScale: 1}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build js
2+
3+
package edwards25519
4+
5+
import "testing/quick"
6+
7+
// Tests in this package use 64-bit math, which is slow under GopherJS. To keep
8+
// test run time reasonable, we reduce the number of test iterations.
9+
var quickCheckConfig32 = &quick.Config{MaxCountScale: 0.5}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build js
2+
3+
package x509
4+
5+
import "testing"
6+
7+
//gopherjs:keep-original
8+
func TestConstraintCases(t *testing.T) {
9+
if testing.Short() {
10+
// These tests are slow under GopherJS. Since GopherJS doesn't touch
11+
// business logic behind them, there's little value in running them all.
12+
// Instead, in the short mode we just just the first few as a smoke test.
13+
nameConstraintsTests = nameConstraintsTests[0:5]
14+
}
15+
_gopherjs_original_TestConstraintCases(t)
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build js
2+
3+
package gif
4+
5+
import "testing"
6+
7+
//gopherjs:keep-original
8+
func FuzzDecode(t *testing.F) {
9+
if testing.Short() {
10+
t.Skip("FuzzDecode is slow, skipping in the short mode.")
11+
}
12+
13+
_gopherjs_original_FuzzDecode(t)
14+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//go:build js
2+
3+
package quick
4+
5+
var maxCountCap int = 0
6+
7+
// GopherJSInternalMaxCountCap sets an upper bound of iterations quick test may
8+
// perform. THIS IS GOPHERJS-INTERNAL API, DO NOT USE IT OUTSIDE OF THE GOPHERJS
9+
// CODEBASE, IT MAY CHANGE OR DISAPPEAR WITHOUT NOTICE.
10+
//
11+
// This function can be used to limit run time of standard library tests which
12+
// use testing/quick with too many iterations for GopherJS to complete in a
13+
// reasonable amount of time. This is a better compromise than disabling a slow
14+
// test entirely.
15+
//
16+
// //gopherjs:keep-original
17+
// func TestFoo(t *testing.T) {
18+
// t.Cleanup(quick.GopherJSInternalMaxCountCap(100))
19+
// _gopherjs_original_TestFoo(t)
20+
// }
21+
22+
func GopherJSInternalMaxCountCap(newCap int) (restore func()) {
23+
previousCap := maxCountCap
24+
maxCountCap = newCap
25+
return func() {
26+
maxCountCap = previousCap
27+
}
28+
}
29+
30+
//gopherjs:keep-original
31+
func (c *Config) getMaxCount() (maxCount int) {
32+
maxCount = c._gopherjs_original_getMaxCount()
33+
if maxCountCap > 0 && maxCount > maxCountCap {
34+
maxCount = maxCountCap
35+
}
36+
return maxCount
37+
}

0 commit comments

Comments
 (0)