Skip to content

Commit

Permalink
test: run long gnovm tests in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
thehowl committed Nov 26, 2024
1 parent 18e4eb9 commit 41ceed5
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions gnovm/pkg/gnolang/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,26 @@ func (nopReader) Read(p []byte) (int, error) { return 0, io.EOF }
// fix a specific test:
// go test -run TestFiles/'^bin1.gno' -short -v -update-golden-tests .
func TestFiles(t *testing.T) {
t.Parallel()

rootDir, err := filepath.Abs("../../../")
require.NoError(t, err)

opts := &test.TestOptions{
RootDir: rootDir,
Output: io.Discard,
Error: io.Discard,
Sync: *withSync,
newOpts := func() *test.TestOptions {
o := &test.TestOptions{
RootDir: rootDir,
Output: io.Discard,
Error: io.Discard,
Sync: *withSync,
}
o.BaseStore, o.TestStore = test.Store(
rootDir, true,
nopReader{}, o.WriterForStore(), io.Discard,
)
return o
}
opts.BaseStore, opts.TestStore = test.Store(
rootDir, true,
nopReader{}, opts.WriterForStore(), io.Discard,
)
// sharedOpts is used for all "short" tests.
sharedOpts := newOpts()

dir := "../../tests/"
fsys := os.DirFS(dir)
Expand All @@ -59,7 +66,8 @@ func TestFiles(t *testing.T) {
return nil
}
subTestName := path[len("files/"):]
if strings.HasSuffix(path, "_long.gno") && testing.Short() {
isLong := strings.HasSuffix(path, "_long.gno")
if isLong && testing.Short() {
t.Run(subTestName, func(t *testing.T) {
t.Skip("skipping in -short")
})
Expand All @@ -73,6 +81,12 @@ func TestFiles(t *testing.T) {

var criticalError error
t.Run(subTestName, func(t *testing.T) {
opts := sharedOpts
if isLong {
// Long tests are run in parallel, and with their own store.
t.Parallel()
opts = newOpts()
}
changed, err := opts.RunFiletest(path, content)
if err != nil {
t.Fatal(err.Error())
Expand All @@ -94,6 +108,8 @@ func TestFiles(t *testing.T) {

// TestStdlibs tests all the standard library packages.
func TestStdlibs(t *testing.T) {
t.Parallel()

rootDir, err := filepath.Abs("../../../")
require.NoError(t, err)

Expand All @@ -102,8 +118,8 @@ func TestStdlibs(t *testing.T) {
if testing.Verbose() {
out = os.Stdout
}
opts := test.NewTestOptions(rootDir, nopReader{}, out, out)
opts.Verbose = true
sharedOpts := test.NewTestOptions(rootDir, nopReader{}, out, out)
sharedOpts.Verbose = true

dir := "../../stdlibs/"
fsys := os.DirFS(dir)
Expand All @@ -118,12 +134,20 @@ func TestStdlibs(t *testing.T) {
fp := filepath.Join(dir, path)
memPkg := gnolang.ReadMemPackage(fp, path)
t.Run(strings.ReplaceAll(memPkg.Path, "/", "-"), func(t *testing.T) {
if testing.Short() {
switch memPkg.Path {
case "bytes", "strconv", "regexp/syntax":
opts := sharedOpts
switch memPkg.Path {
case "bytes", "strconv", "regexp/syntax":
if testing.Short() {
t.Skip("Skipped because of -short, and this stdlib is very long currently.")
} else {
t.Parallel()

// Long test; run in parallel at the end with own store.
opts = test.NewTestOptions(rootDir, nopReader{}, out, out)
opts.Verbose = true
}
}

err := test.Test(memPkg, "", opts)
if !testing.Verbose() {
t.Log(capture.String())
Expand Down

0 comments on commit 41ceed5

Please sign in to comment.