Skip to content

Commit

Permalink
test: make tests run in parallel (#1312)
Browse files Browse the repository at this point in the history
## Description

This PR simply introduces `t.Parallel()` for unit tests that can support
it.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Co-authored-by: Guilhem Fanton <8671905+gfanton@users.noreply.github.com>
  • Loading branch information
zivkovicmilos and gfanton authored Nov 9, 2023
1 parent c33c9f2 commit e803c45
Show file tree
Hide file tree
Showing 161 changed files with 1,765 additions and 143 deletions.
5 changes: 5 additions & 0 deletions gno.land/cmd/gnoland/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
)

func TestStartInitialize(t *testing.T) {
t.Parallel()

cases := []struct {
args []string
}{
Expand All @@ -23,8 +25,11 @@ func TestStartInitialize(t *testing.T) {
os.Chdir(filepath.Join("..", "..")) // go to repo's root dir

for _, tc := range cases {
tc := tc
name := strings.Join(tc.args, " ")
t.Run(name, func(t *testing.T) {
t.Parallel()

mockOut := bytes.NewBufferString("")
mockErr := bytes.NewBufferString("")
io := commands.NewTestIO()
Expand Down
2 changes: 2 additions & 0 deletions gno.land/pkg/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ import (
)

func TestTestdata(t *testing.T) {
t.Parallel()

RunGnolandTestscripts(t, "testdata")
}
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/alloc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func TestAllocSizes(t *testing.T) {
t.Parallel()

// go elemental
println("_allocPointer", unsafe.Sizeof(&StructValue{}))
println("_allocSlice", unsafe.Sizeof([]byte("12345678901234567890123456789012345678901234567890")))
Expand Down
32 changes: 32 additions & 0 deletions gnovm/pkg/gnolang/gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

// run empty main().
func TestRunEmptyMain(t *testing.T) {
t.Parallel()

m := NewMachine("test", nil)
main := FuncD("main", nil, nil, nil)
m.RunDeclaration(main)
Expand All @@ -21,6 +23,8 @@ func TestRunEmptyMain(t *testing.T) {

// run main() with a for loop.
func TestRunLoopyMain(t *testing.T) {
t.Parallel()

m := NewMachine("test", nil)
c := `package test
func main() {
Expand All @@ -36,6 +40,8 @@ func main() {
}

func TestEval(t *testing.T) {
t.Parallel()

m := NewMachine("test", nil)
c := `package test
func next(i int) int {
Expand Down Expand Up @@ -64,6 +70,8 @@ func assertOutput(t *testing.T, input string, output string) {
}

func TestRunMakeStruct(t *testing.T) {
t.Parallel()

assertOutput(t, `package test
type Outfit struct {
Scarf string
Expand All @@ -90,6 +98,8 @@ func main() {
}

func TestRunReturnStruct(t *testing.T) {
t.Parallel()

assertOutput(t, `package test
type MyStruct struct {
FieldA string
Expand Down Expand Up @@ -160,6 +170,8 @@ type Struct1 struct {
}

func TestModifyTypeAsserted(t *testing.T) {
t.Parallel()

x := Struct1{1, 1}
var v interface{} = x
x2 := v.(Struct1)
Expand All @@ -176,6 +188,8 @@ type Interface1 interface {
}

func TestTypeConversion(t *testing.T) {
t.Parallel()

x := 1
var v interface{} = x
if _, ok := v.(Interface1); ok {
Expand All @@ -193,6 +207,8 @@ func TestTypeConversion(t *testing.T) {
}

func TestSomething(t *testing.T) {
t.Parallel()

type Foo struct {
X interface{}
}
Expand All @@ -210,6 +226,8 @@ func TestSomething(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestDeferOrder(t *testing.T) {
t.Parallel()

a := func() func(int, int) int {
fmt.Println("a constructed")
return func(x int, y int) int {
Expand Down Expand Up @@ -238,6 +256,8 @@ func TestDeferOrder(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestCallOrder(t *testing.T) {
t.Parallel()

a := func() func(int, int) int {
fmt.Println("a constructed")
return func(x int, y int) int {
Expand All @@ -264,6 +284,8 @@ func TestCallOrder(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestBinaryShortCircuit(t *testing.T) {
t.Parallel()

tr := func() bool {
fmt.Println("t called")
return true
Expand All @@ -281,6 +303,8 @@ func TestBinaryShortCircuit(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestSwitchDefine(t *testing.T) {
t.Parallel()

var x interface{} = 1
switch y := x.(type) {
case int:
Expand All @@ -292,6 +316,8 @@ func TestSwitchDefine(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestBinaryCircuit(t *testing.T) {
t.Parallel()

tr := func() bool {
fmt.Println("tr() called")
return true
Expand All @@ -316,6 +342,8 @@ func TestBinaryCircuit(t *testing.T) {
}

func TestMultiAssignment(t *testing.T) {
t.Parallel()

buf := make([]int, 4)
ref := func(i int) *int {
fmt.Printf("ref(%v) called\n", i)
Expand All @@ -342,6 +370,8 @@ func TestMultiAssignment(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestCallLHS(t *testing.T) {
t.Parallel()

x := 1
xptr := func() *int {
return &x
Expand All @@ -352,6 +382,8 @@ func TestCallLHS(t *testing.T) {

// XXX is there a way to test in Go as well as Gno?
func TestCallFieldLHS(t *testing.T) {
t.Parallel()

type str struct {
X int
}
Expand Down
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/go2gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
)

func TestParseForLoop(t *testing.T) {
t.Parallel()

gocode := `package main
func main(){
for i:=0; i<10; i++ {
Expand Down
4 changes: 4 additions & 0 deletions gnovm/pkg/gnolang/gonative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ D:
}

func TestGoNativeDefine3(t *testing.T) {
t.Parallel()

// Create package foo and define Foo.
out := new(bytes.Buffer)
pkg := NewPackageNode("foo", "test.foo", nil)
Expand Down Expand Up @@ -135,6 +137,8 @@ D:
}

func TestCrypto(t *testing.T) {
t.Parallel()

addr := crypto.Address{}
store := gonativeTestStore()
tv := Go2GnoValue(nilAllocator, store, reflect.ValueOf(addr))
Expand Down
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

// Tries to reproduce the bug #1036 on all registered types
func TestAminoJSONRegisteredTypes(t *testing.T) {
t.Parallel()

for _, typ := range Package.Types {
// Instantiate registered type
x := reflect.New(typ.Type).Interface()
Expand Down
4 changes: 4 additions & 0 deletions gnovm/pkg/gnolang/precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
)

func TestPrecompile(t *testing.T) {
t.Parallel()

cases := []struct {
name string
source string
Expand Down Expand Up @@ -56,6 +58,8 @@ func TestPrecompile(t *testing.T) {
for _, c := range cases {
c := c // scopelint
t.Run(c.name, func(t *testing.T) {
t.Parallel()

// parse gno
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "foo.go", c.source, parser.ParseComments)
Expand Down
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/values_conversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func TestConvertUntypedBigdecToFloat(t *testing.T) {
t.Parallel()

dst := &TypedValue{}

dec, err := apd.New(-math.MaxInt64, -4).SetFloat64(math.SmallestNonzeroFloat64 / 2)
Expand Down
4 changes: 4 additions & 0 deletions gnovm/pkg/repl/repl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ func TestRepl(t *testing.T) {
}

func TestReplOpts(t *testing.T) {
t.Parallel()

require := require.New(t)

r := NewRepl(WithStd(nil, nil, nil), WithStore(nil))
Expand All @@ -212,6 +214,8 @@ func TestReplOpts(t *testing.T) {
}

func TestReplReset(t *testing.T) {
t.Parallel()

require := require.New(t)

r := NewRepl()
Expand Down
2 changes: 2 additions & 0 deletions gnovm/tests/selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func _printValue(x interface{}) {
}

func TestSelectors(t *testing.T) {
t.Parallel()

x0 := struct{ F0 int }{1}
_printValue(x0.F0) // *ST.F0
// F:0
Expand Down
2 changes: 2 additions & 0 deletions misc/docker-integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const (
)

func TestDockerIntegration(t *testing.T) {
t.Parallel()

tmpdir, err := os.MkdirTemp(os.TempDir(), "*-gnoland-integration")
require.NoError(t, err)

Expand Down
14 changes: 14 additions & 0 deletions tm2/pkg/amino/amino_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

func TestMarshal(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()

type SimpleStruct struct {
Expand All @@ -35,6 +37,8 @@ func TestMarshal(t *testing.T) {
}

func TestUnmarshalReader(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()

type SimpleStruct struct {
Expand Down Expand Up @@ -65,6 +69,8 @@ type stringWrapper struct {
}

func TestUnmarshalReaderSize(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()

s1 := stringWrapper{"foo"}
Expand All @@ -82,6 +88,8 @@ func TestUnmarshalReaderSize(t *testing.T) {
}

func TestUnmarshalReaderSizeLimit(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()

s1 := stringWrapper{"foo"}
Expand All @@ -101,6 +109,8 @@ func TestUnmarshalReaderSizeLimit(t *testing.T) {
}

func TestUnmarshalReaderTooLong(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()

type SimpleStruct struct {
Expand All @@ -125,6 +135,8 @@ func TestUnmarshalReaderTooLong(t *testing.T) {
}

func TestUnmarshalBufferedWritesReads(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()
buf := bytes.NewBuffer(nil)

Expand Down Expand Up @@ -155,6 +167,8 @@ func TestUnmarshalBufferedWritesReads(t *testing.T) {
}

func TestBoolPointers(t *testing.T) {
t.Parallel()

cdc := amino.NewCodec()
type SimpleStruct struct {
BoolPtrTrue *bool
Expand Down
4 changes: 4 additions & 0 deletions tm2/pkg/amino/binary_encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import (
)

func TestEncodeFieldNumberAndTyp3_1(t *testing.T) {
t.Parallel()

buf := new(bytes.Buffer)
err := encodeFieldNumberAndTyp3(buf, 1, Typ3ByteLength)
assert.Nil(t, err)
assert.Equal(t, []byte{byte(0x01<<3 | Typ3ByteLength)}, buf.Bytes())
}

func TestEncodeFieldNumberAndTyp3_2(t *testing.T) {
t.Parallel()

buf := new(bytes.Buffer)
err := encodeFieldNumberAndTyp3(buf, 2, Typ3ByteLength)
assert.Nil(t, err)
Expand Down
Loading

0 comments on commit e803c45

Please sign in to comment.