Skip to content
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

manage long and special tests effectively #588

Closed
ilgooz opened this issue Mar 10, 2023 · 4 comments · Fixed by #3119
Closed

manage long and special tests effectively #588

ilgooz opened this issue Mar 10, 2023 · 4 comments · Fixed by #3119
Labels
help wanted Want to contribute? We recommend these issues. investigating This behavior is still being tested out

Comments

@ilgooz
Copy link
Contributor

ilgooz commented Mar 10, 2023

No description provided.

@ilgooz ilgooz added the bug label Mar 10, 2023
@grepsuzette
Copy link
Contributor

Confirmed (cd tests; go test).
Hangs after outputing (just copying the end):

stack 1: file{ package main; func init.0() { (const (println func(xs ...interface{})()))((const ("here" string))) }; func main() { init<VPUverse(0)>() } }
stack 0: package(main)
------------------------
OUTPUT:
 
in
inCall
Hello &{foo}
foo
code: foo
2
inCall
Hello {foo}
foo
inCall
a: {}
A
1
1
A
<nil>
1
1
inCall
Hello {foo}
foo
test 2
test 2
test
2 test
{test}
<nil>
inCall
Hello {foo}
foo
0
<nil>
{}
test
Myint: 3 3
Myint: 4 4
hi
foo
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115]
AAAAAA
0 1 2
0 1 2 3
0 1 2
0 1 2 3
test
12
map[b:one round:12]
foo
map[] true
[0 0 0 0]
[hellobar hellofoo worldmachin worldtruc]
[hellobar hellofoo worldmachin worldtruc]
[hellobar worldmachin]
&{ map[Accept-Encoding:[gzip]]}
true false
v: 
 false
not exists
0
1 test
&{}
&{}
{test 1s}
 false
bidule true
[hellobar hellofoo worldmachin worldtruc]
[hellobar hellofoo worldmachin worldtruc]
-1
[187 141 73 89 101 229 33 106 226 63 117 234 117 149 230 21]

Maybe run a git bisect to identify when it started to block.

@ilgooz ilgooz removed the bug label Mar 13, 2023
@thehowl
Copy link
Member

thehowl commented Mar 13, 2023

This is actually not blocking, it's just because it's running a very long test. It is also not reproduced on the CI as the CI runs the commands from make test, and never runs a simple go test on the tests folder.

The problem is that there are in the files/ directory some tests which have the _long suffix, and are actually not executed using the makefile (as the -test.short flag is passed to go test). These are very very long and more likely meant for those delving deep into optimisation- and internals-land.

I think this issue still raises two good questions: shouldn't we at least sporadically run some of these on the CI, and should we make it clearer that the "proper" way to run files in tests is through make test?

For the first one, I think a good strategy could be to run the long file tests with continue-on-error set to true (I think if this is set to true, github may mark the workflow as passing even though this one is still running?). If they still take >30m, we could subdivide them further.

(While looking at this, I also found that we probably don't test go files in examples/, nor all the stdlibs, because make test only specifies a subset of packages from stdlibs. @moul should I make an issue for this, or is this intended)?

@moul
Copy link
Member

moul commented Mar 13, 2023

This test is too lengthy and prone to timeouts for most users, so it should be disabled and reserved for advanced users who are conducting fuzzing tests. We must find a balance between never running the test and having a slow CI.

To ensure that tests are completely disabled when someone runs cd tests; go test ., we should split the Makefile into two parts. The main Makefile should be shorter and easier to use for most people, while the second Makefile should contain advanced scripts and rules that are available for autonomous advanced users only. Additionally, we should document how to run these advanced tests.

@thehowl shared an intriguing idea for the CI that is reminiscent of fuzzing. This involves randomly disabling tests and running them iteratively until a specified timeout is reached, which would be considered a "success" in our case.

@moul
Copy link
Member

moul commented Mar 13, 2023

You beat me to it, @thehowl!

I believe we can continue discussing this issue. But up to you.

I just remembered that we have one more type of ignored tests: the func TestFlappy ones. By default, these tests are skipped when running go test, but they can be executed from the Makefile and are run multiple times by the CI, looking for at least one successful. Although this isn't ideal, it's still better than completely skipping the test.

@moul moul changed the title Running go test at /tests hangs manage long and special tests effectively Mar 13, 2023
@moul moul added help wanted investigating This behavior is still being tested out labels Mar 13, 2023
@moul moul moved this to 🔵 Not Needed for Launch in 🚀 The Launch [DEPRECATED] Sep 5, 2023
@moul moul added this to the 💡Someday/Maybe milestone Sep 6, 2023
@Kouteki Kouteki added help wanted Want to contribute? We recommend these issues. and removed help wanted labels Oct 2, 2024
r3v4s pushed a commit to gnoswap-labs/gno that referenced this issue Dec 10, 2024
This PR tackles a large amount of improvements in our current internal
testing systems for the gnovm, as well as those for `gno test`. The
primary target is the execution of filetests; however many improvements
have been implemented to remove dead or duplicate code, and bring over
some of the improvements that have been implemented in tests to
filetests, when they come at little added "cost".

The biggest headline concerns the execution of filetests. I wrote the
specific improvements undertaken in a [blog post on "diary of a
gnome"](https://gno.howl.moe/faster-tests/), but here's a side-by-side
comparison of the execution in this PR (left) and the execution on
master (right).


![filetests](https://github.com/user-attachments/assets/049680f2-baeb-4f24-8f0f-60ae5fa4bce5)

- Fixes gnolang#1084
- Fixes gnolang#2826 (by addressing root cause of slowness)
- Fixes gnolang#588, only running `_long` filetests on master and generally
speeding up test execution.

## Impact

- Test context (tests and filetests)
- Tests and filetests now share the same `test.Store` when running.
Coupled with `test.LoadImports`, it allows us to "eagerly load" imports
ahead of the test execution, and save it in the store. This is the
primary performance improvement of this PR, as all pure packages can be
run and preprocessed only once, whereas before it was once per package,
and once per filetest. (More info in the blog post.)
- One of the consequences of this is that package initialization happens
outside of the test; so a filetest can no longer check the output of a
`println` used in package initialization.
- The default user no longer has 200 gnot by default. There are two
mechanisms that make this unnecessary: `// SEND:`, and
`std.TestIssueCoin`. Some test balances had to be updated.
- Filetests
	- Running filetests in `gno test -v` now also prints their output.
- Realm tests are no longer executed in `main.gno`, but in a filename
following the name of the filetest; this changed some `// Realm:`
directives.
- The sytem to read directives and update them in the filetests has been
re-written, and should now be more resilient and with fewer
"exceptions". This means that leading and trailing whitespace in output
now is correctly considered as output, leading to the addition of many
empty `//` in the tests.
- `// Error:` directives are now treated the same as everything else;
and are updated if the `-update-golden-tests` flag is passed.
- Removed the `imports` metric from the runtime metrics, as it's now no
longer straightforward to calculate (given that imports are loaded
"eagerly").
- Removed support for different "modes" of importing stdlibs; further
removing support for gonative (gnolang#1361). The remaining gonative libraries
are `os`, `fmt`, `encoding/json`, `internal/os_test` and `math/big`.
This removes the `-with-native-fallback` flag from `gno test`.
- Consequently, filetests ending with `_native.gno` have largely been
removed, and those ending with `_stdlibs.go` have had their suffix
removed.
- Some files testing `gonative` types and functions which were only used
in a small subset of these tests, have been removed.
- Tests
- `gno test`, for testing packages, created a `main_test.gno` file that
is then called directly from the machine on each test. This creates two
identifiers, `tests` and `runtest`, which could come into conflict with
those defined by the tests themselves. We now call `testing.RunTest`
directly, without an intermediary.
- Exports in the normal tests (ie. defined in `pkg`) are now visible in
the tests of `pkg_test`. This is most useful for some standard library
tests, where there often is an `export_test.go` with the sole scope of
exporting some internal functions and methods for testing in the "real"
testing file.
- `gno lint`, and other occasions where we use `issueFromError` (like
when parsing errors in `gno test`), will now also print the column of
the error if given.

## Summary of internal changes

- pkg/gnolang
	- `TestFiles` is the new function running the filetests.
- `eval_test.go` has been removed, moving some of its improvements over
to `TestFiles`, and reducing the scope of the corresponding tests in
`debugger.go`, to what it's actually supposed to test for.
- As a consequence of removing all of type mappings in `imports.go`, I
removed `SetStrictGo2GnoMapping` in favour of always being "strict", and
not allowing defining native types of defined types any more.
- The tests in `gonative_test` where primarily related to this, so I
removed them. Similarly for `preprocess_test`.
- `TestFunc` / `TestMemPackage` have been removed as redundant,
including some of their features in `cmd/go/test.go` (like supporting
exporting symbols in `_test.gno` files)
- The `Store` no longer has `ClearCache` and `SetStrictGo2GnoMapping`;
`ClearCache` now has a better substitute in `BeginTransaction`.
- the `testing` stdlib no longer caches `matchPat` and `matchString` as
pure packages should not be able to modify their values during
execution, and as a result of other changes this was failing.
- The tests/ directory has been removed / moved to `gnovm/pkg/test`.
This directory should eventually contain the internal code for `gno
test` as well; but for now I wanted to clean `tests` to ensure it is a
directory just for integration tests, rather than code and testing
systems.
- `TestMachine` and `TestStore` have been renamed to Machine and Store,
to avoid redundancy with the `test` package name.
- Removed plenty instructions in `gnovm/Makefile` as now most tests are
just in `pkg/gnolang`.
- I removed `MsgContext.Msg` as unused. It can be re-added later if
necessary.
- In the CI, tests are now run with `-short`, at least until we figure
out how to make the VM efficient enough to run these tests. Aside from
some filetests, this now excludes some stdlibs: `bytes`, `strconv`,
`regexp/syntax`. I accept other proposals that could make us have fast
tests on PR's, while still testing (mostly) everything.

---
[![Open Source
Saturday](https://img.shields.io/badge/%E2%9D%A4%EF%B8%8F-open%20source%20saturday-F64060.svg)](https://lu.ma/open-source-saturday-torino)

---------

Co-authored-by: Marc Vertes <[email protected]>
albttx pushed a commit that referenced this issue Jan 10, 2025
This PR tackles a large amount of improvements in our current internal
testing systems for the gnovm, as well as those for `gno test`. The
primary target is the execution of filetests; however many improvements
have been implemented to remove dead or duplicate code, and bring over
some of the improvements that have been implemented in tests to
filetests, when they come at little added "cost".

The biggest headline concerns the execution of filetests. I wrote the
specific improvements undertaken in a [blog post on "diary of a
gnome"](https://gno.howl.moe/faster-tests/), but here's a side-by-side
comparison of the execution in this PR (left) and the execution on
master (right).


![filetests](https://github.com/user-attachments/assets/049680f2-baeb-4f24-8f0f-60ae5fa4bce5)

- Fixes #1084
- Fixes #2826 (by addressing root cause of slowness)
- Fixes #588, only running `_long` filetests on master and generally
speeding up test execution.

## Impact

- Test context (tests and filetests)
- Tests and filetests now share the same `test.Store` when running.
Coupled with `test.LoadImports`, it allows us to "eagerly load" imports
ahead of the test execution, and save it in the store. This is the
primary performance improvement of this PR, as all pure packages can be
run and preprocessed only once, whereas before it was once per package,
and once per filetest. (More info in the blog post.)
- One of the consequences of this is that package initialization happens
outside of the test; so a filetest can no longer check the output of a
`println` used in package initialization.
- The default user no longer has 200 gnot by default. There are two
mechanisms that make this unnecessary: `// SEND:`, and
`std.TestIssueCoin`. Some test balances had to be updated.
- Filetests
	- Running filetests in `gno test -v` now also prints their output.
- Realm tests are no longer executed in `main.gno`, but in a filename
following the name of the filetest; this changed some `// Realm:`
directives.
- The sytem to read directives and update them in the filetests has been
re-written, and should now be more resilient and with fewer
"exceptions". This means that leading and trailing whitespace in output
now is correctly considered as output, leading to the addition of many
empty `//` in the tests.
- `// Error:` directives are now treated the same as everything else;
and are updated if the `-update-golden-tests` flag is passed.
- Removed the `imports` metric from the runtime metrics, as it's now no
longer straightforward to calculate (given that imports are loaded
"eagerly").
- Removed support for different "modes" of importing stdlibs; further
removing support for gonative (#1361). The remaining gonative libraries
are `os`, `fmt`, `encoding/json`, `internal/os_test` and `math/big`.
This removes the `-with-native-fallback` flag from `gno test`.
- Consequently, filetests ending with `_native.gno` have largely been
removed, and those ending with `_stdlibs.go` have had their suffix
removed.
- Some files testing `gonative` types and functions which were only used
in a small subset of these tests, have been removed.
- Tests
- `gno test`, for testing packages, created a `main_test.gno` file that
is then called directly from the machine on each test. This creates two
identifiers, `tests` and `runtest`, which could come into conflict with
those defined by the tests themselves. We now call `testing.RunTest`
directly, without an intermediary.
- Exports in the normal tests (ie. defined in `pkg`) are now visible in
the tests of `pkg_test`. This is most useful for some standard library
tests, where there often is an `export_test.go` with the sole scope of
exporting some internal functions and methods for testing in the "real"
testing file.
- `gno lint`, and other occasions where we use `issueFromError` (like
when parsing errors in `gno test`), will now also print the column of
the error if given.

## Summary of internal changes

- pkg/gnolang
	- `TestFiles` is the new function running the filetests.
- `eval_test.go` has been removed, moving some of its improvements over
to `TestFiles`, and reducing the scope of the corresponding tests in
`debugger.go`, to what it's actually supposed to test for.
- As a consequence of removing all of type mappings in `imports.go`, I
removed `SetStrictGo2GnoMapping` in favour of always being "strict", and
not allowing defining native types of defined types any more.
- The tests in `gonative_test` where primarily related to this, so I
removed them. Similarly for `preprocess_test`.
- `TestFunc` / `TestMemPackage` have been removed as redundant,
including some of their features in `cmd/go/test.go` (like supporting
exporting symbols in `_test.gno` files)
- The `Store` no longer has `ClearCache` and `SetStrictGo2GnoMapping`;
`ClearCache` now has a better substitute in `BeginTransaction`.
- the `testing` stdlib no longer caches `matchPat` and `matchString` as
pure packages should not be able to modify their values during
execution, and as a result of other changes this was failing.
- The tests/ directory has been removed / moved to `gnovm/pkg/test`.
This directory should eventually contain the internal code for `gno
test` as well; but for now I wanted to clean `tests` to ensure it is a
directory just for integration tests, rather than code and testing
systems.
- `TestMachine` and `TestStore` have been renamed to Machine and Store,
to avoid redundancy with the `test` package name.
- Removed plenty instructions in `gnovm/Makefile` as now most tests are
just in `pkg/gnolang`.
- I removed `MsgContext.Msg` as unused. It can be re-added later if
necessary.
- In the CI, tests are now run with `-short`, at least until we figure
out how to make the VM efficient enough to run these tests. Aside from
some filetests, this now excludes some stdlibs: `bytes`, `strconv`,
`regexp/syntax`. I accept other proposals that could make us have fast
tests on PR's, while still testing (mostly) everything.

---
[![Open Source
Saturday](https://img.shields.io/badge/%E2%9D%A4%EF%B8%8F-open%20source%20saturday-F64060.svg)](https://lu.ma/open-source-saturday-torino)

---------

Co-authored-by: Marc Vertes <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Want to contribute? We recommend these issues. investigating This behavior is still being tested out
Projects
Status: 🔵 Not Needed for Launch
Development

Successfully merging a pull request may close this issue.

5 participants