Skip to content

Make slow stdlib tests faster. #1327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions compiler/natives/src/crypto/ed25519/ed25519vectors_test.go

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build js

package field

import (
"testing"
"testing/quick"
)

//gopherjs:keep-original
func TestAliasing(t *testing.T) {
// The test heavily uses 64-bit math, which is slow under GopherJS. Reducing
// the number of iterations makes run time more manageable.
t.Cleanup(quick.GopherJSInternalMaxCountCap(100))
_gopherjs_original_TestAliasing(t)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build js

package field

import "testing/quick"

// Tests in this package use 64-bit math, which is slow under GopherJS. To keep
// test run time reasonable, we reduce the number of test iterations.
var quickCheckConfig1024 = &quick.Config{MaxCountScale: 10}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build js

package edwards25519

import "testing/quick"

// Tests in this package use 64-bit math, which is slow under GopherJS. To keep
// test run time reasonable, we reduce the number of test iterations.
var quickCheckConfig1024 = &quick.Config{MaxCountScale: 1}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build js

package edwards25519

import "testing/quick"

// Tests in this package use 64-bit math, which is slow under GopherJS. To keep
// test run time reasonable, we reduce the number of test iterations.
var quickCheckConfig32 = &quick.Config{MaxCountScale: 0.5}
16 changes: 16 additions & 0 deletions compiler/natives/src/crypto/x509/name_constraints_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build js

package x509

import "testing"

//gopherjs:keep-original
func TestConstraintCases(t *testing.T) {
if testing.Short() {
// These tests are slow under GopherJS. Since GopherJS doesn't touch
// business logic behind them, there's little value in running them all.
// Instead, in the short mode we just just the first few as a smoke test.
nameConstraintsTests = nameConstraintsTests[0:5]
}
_gopherjs_original_TestConstraintCases(t)
}
14 changes: 14 additions & 0 deletions compiler/natives/src/image/gif/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build js

package gif

import "testing"

//gopherjs:keep-original
func FuzzDecode(t *testing.F) {
if testing.Short() {
t.Skip("FuzzDecode is slow, skipping in the short mode.")
}

_gopherjs_original_FuzzDecode(t)
}
37 changes: 37 additions & 0 deletions compiler/natives/src/testing/quick/quick.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//go:build js

package quick

var maxCountCap int = 0

// GopherJSInternalMaxCountCap sets an upper bound of iterations quick test may
// perform. THIS IS GOPHERJS-INTERNAL API, DO NOT USE IT OUTSIDE OF THE GOPHERJS
// CODEBASE, IT MAY CHANGE OR DISAPPEAR WITHOUT NOTICE.
//
// This function can be used to limit run time of standard library tests which
// use testing/quick with too many iterations for GopherJS to complete in a
// reasonable amount of time. This is a better compromise than disabling a slow
// test entirely.
//
// //gopherjs:keep-original
// func TestFoo(t *testing.T) {
// t.Cleanup(quick.GopherJSInternalMaxCountCap(100))
// _gopherjs_original_TestFoo(t)
// }

func GopherJSInternalMaxCountCap(newCap int) (restore func()) {
previousCap := maxCountCap
maxCountCap = newCap
return func() {
maxCountCap = previousCap
}
}

//gopherjs:keep-original
func (c *Config) getMaxCount() (maxCount int) {
maxCount = c._gopherjs_original_getMaxCount()
if maxCountCap > 0 && maxCount > maxCountCap {
maxCount = maxCountCap
}
return maxCount
}
Loading