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

go/oasis-test-runner: List all available scenarios #3044

Merged
merged 3 commits into from
Jun 24, 2020
Merged

Conversation

tjanez
Copy link
Member

@tjanez tjanez commented Jun 24, 2020

List all available scenarios if command was invoked with a particular scenario that was not found.

For example, running .buildkite/scripts/test_e2e.sh --test storage-sync where storage-sync scenario doesn't exist, now returns:

+ WORKDIR=/home/tadej/Oasis/oasis-core
+ runtime_target=default
+ [[ '' == \i\n\t\e\l\-\s\g\x ]]
+ [[ '' != '' ]]
+ node_binary=/home/tadej/Oasis/oasis-core/go/oasis-node/oasis-node
+ test_runner_binary=/home/tadej/Oasis/oasis-core/go/oasis-test-runner/oasis-test-runner
+ [[ '' != '' ]]
+ ias_mock=true
+ set +x
+ /home/tadej/Oasis/oasis-core/go/oasis-test-runner/oasis-test-runner --basedir.no_cleanup --e2e.node.binary /home/tadej/Oasis/oasis-core/go/oasis-node/oasis-node --e2e/runtime.client.binary_dir /home/tadej/Oasis/oasis-core/target/default/debug --e2e/runtime.runtime.binary_dir /home/tadej/Oasis/oasis-core/target/default/debug --e2e/runtime.runtime.loader /home/tadej/Oasis/oasis-core/target/default/debug/oasis-core-runtime-loader --e2e/runtime.tee_hardware '' --e2e/runtime.ias.mock=true --remote-signer.binary /home/tadej/Oasis/oasis-core/go/oasis-remote-signer/oasis-remote-signer --log.level info --test storage-sync
level=error module=test-runner caller=root.go:279 ts=2020-06-24T08:07:30.560481983Z msg="unknown scenario" scenario=storage-sync
Error: root: unknown scenario: storage-sync
Available scenarios:
e2e/identity-cli
e2e/runtime/byzantine/executor-honest
e2e/runtime/byzantine/executor-straggler
e2e/runtime/byzantine/executor-wrong
e2e/runtime/byzantine/merge-honest
e2e/runtime/byzantine/merge-straggler
e2e/runtime/byzantine/merge-wrong
e2e/runtime/debond
e2e/runtime/dump-restore
e2e/runtime/early-query
e2e/runtime/gas-fees/runtimes
e2e/runtime/gas-fees/staking
e2e/runtime/gas-fees/staking-dump-restore
e2e/runtime/halt-restore
e2e/runtime/keymanager-replication
e2e/runtime/keymanager-restart
e2e/runtime/keymanager-upgrade
e2e/runtime/late-start
e2e/runtime/multiple-runtimes
e2e/runtime/node-shutdown
e2e/runtime/node-upgrade
e2e/runtime/node-upgrade-cancel
e2e/runtime/registry-cli
e2e/runtime/runtime
e2e/runtime/runtime-dynamic
e2e/runtime/runtime-encryption
e2e/runtime/runtime-prune
e2e/runtime/sentry
e2e/runtime/sentry-encryption
e2e/runtime/stake-cli
e2e/runtime/storage-sync
e2e/runtime/txsource-multi
e2e/runtime/txsource-multi-short
remote-signer/basic

@tjanez tjanez added c:testing Category: testing c:cli Category: command line interface labels Jun 24, 2020
@tjanez tjanez self-assigned this Jun 24, 2020
go/oasis-test-runner/cmd/common/common.go Show resolved Hide resolved
@@ -75,7 +75,7 @@ func RootCmd() *cobra.Command {
// Execute spawns the main entry point after handing the config file.
func Execute() {
if err := rootCmd.Execute(); err != nil {
nodeCommon.EarlyLogAndExit(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nodeCommon.EarlyLogAndExit() prints the error to stderr:

// EarlyLogAndExit logs the error and exits.
//
// Note: This routine should only be used prior to the logging system
// being initialized.
func EarlyLogAndExit(err error) {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

which results in the same error message being outputted twice.

For example:

$ .buildkite/scripts/test_e2e.sh --test storage-sync
+ WORKDIR=/home/tadej/Oasis/oasis-core
+ runtime_target=default
+ [[ '' == \i\n\t\e\l\-\s\g\x ]]
+ [[ '' != '' ]]
+ node_binary=/home/tadej/Oasis/oasis-core/go/oasis-node/oasis-node
+ test_runner_binary=/home/tadej/Oasis/oasis-core/go/oasis-test-runner/oasis-test-runner
+ [[ '' != '' ]]
+ ias_mock=true
+ set +x
+ /home/tadej/Oasis/oasis-core/go/oasis-test-runner/oasis-test-runner --basedir.no_cleanup --e2e.node.binary /home/tadej/Oasis/oasis-core/go/oasis-node/oasis-node --e2e/runtime.client.binary_dir /home/tadej/Oasis/oasis-core/target/default/debug --e2e/runtime.runtime.binary_dir /home/tadej/Oasis/oasis-core/target/default/debug --e2e/runtime.runtime.loader /home/tadej/Oasis/oasis-core/target/default/debug/oasis-core-runtime-loader --e2e/runtime.tee_hardware '' --e2e/runtime.ias.mock=true --remote-signer.binary /home/tadej/Oasis/oasis-core/go/oasis-remote-signer/oasis-remote-signer --log.level info --test storage-sync
level=error module=test-runner caller=root.go:279 ts=2020-06-24T08:24:40.945179021Z msg="unknown scenario" scenario=storage-sync
Error: root: unknown scenario: storage-sync
Available scenarios:
e2e/identity-cli
e2e/runtime/byzantine/executor-honest
e2e/runtime/byzantine/executor-straggler
e2e/runtime/byzantine/executor-wrong
e2e/runtime/byzantine/merge-honest
e2e/runtime/byzantine/merge-straggler
e2e/runtime/byzantine/merge-wrong
e2e/runtime/debond
e2e/runtime/dump-restore
e2e/runtime/early-query
e2e/runtime/gas-fees/runtimes
e2e/runtime/gas-fees/staking
e2e/runtime/gas-fees/staking-dump-restore
e2e/runtime/halt-restore
e2e/runtime/keymanager-replication
e2e/runtime/keymanager-restart
e2e/runtime/keymanager-upgrade
e2e/runtime/late-start
e2e/runtime/multiple-runtimes
e2e/runtime/node-shutdown
e2e/runtime/node-upgrade
e2e/runtime/node-upgrade-cancel
e2e/runtime/registry-cli
e2e/runtime/runtime
e2e/runtime/runtime-dynamic
e2e/runtime/runtime-encryption
e2e/runtime/runtime-prune
e2e/runtime/sentry
e2e/runtime/sentry-encryption
e2e/runtime/stake-cli
e2e/runtime/storage-sync
e2e/runtime/txsource-multi
e2e/runtime/txsource-multi-short
remote-signer/basic
root: unknown scenario: storage-sync
Available scenarios:
e2e/identity-cli
e2e/runtime/byzantine/executor-honest
e2e/runtime/byzantine/executor-straggler
e2e/runtime/byzantine/executor-wrong
e2e/runtime/byzantine/merge-honest
e2e/runtime/byzantine/merge-straggler
e2e/runtime/byzantine/merge-wrong
e2e/runtime/debond
e2e/runtime/dump-restore
e2e/runtime/early-query
e2e/runtime/gas-fees/runtimes
e2e/runtime/gas-fees/staking
e2e/runtime/gas-fees/staking-dump-restore
e2e/runtime/halt-restore
e2e/runtime/keymanager-replication
e2e/runtime/keymanager-restart
e2e/runtime/keymanager-upgrade
e2e/runtime/late-start
e2e/runtime/multiple-runtimes
e2e/runtime/node-shutdown
e2e/runtime/node-upgrade
e2e/runtime/node-upgrade-cancel
e2e/runtime/registry-cli
e2e/runtime/runtime
e2e/runtime/runtime-dynamic
e2e/runtime/runtime-encryption
e2e/runtime/runtime-prune
e2e/runtime/sentry
e2e/runtime/sentry-encryption
e2e/runtime/stake-cli
e2e/runtime/storage-sync
e2e/runtime/txsource-multi
e2e/runtime/txsource-multi-short
remote-signer/basic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who prints the first error message, does cobra do that internally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Cobra does that in ExecuteC():

// If root command has SilentErrors flagged,
// all subcommands should respect it
if !cmd.SilenceErrors && !c.SilenceErrors {
	c.Println("Error:", err.Error())
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like our helper better as it prints to stderr while cobra seems to print to stdout? Could we instead set SilenceErrors (maybe this needs to be done in other places as well as we use EarlyLogAndExit everywhere)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like our helper better as it prints to stderr while cobra seems to print to stdout?

Cobra's Command.Println() defaults to printing to stderr.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have this EarlyLogAndExit at all then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is still useful for cases where we want to exit and print an error before we execute Cobra's Execute().

I found two such cases in go/oasis-test-runner:

I've removed other uses in go/oasis-test-runner.

For other parts of the code base, I can file an issue to systematically check that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other parts of the code base, I can file an issue to systematically check that.

Done: #3048.

@codecov
Copy link

codecov bot commented Jun 24, 2020

Codecov Report

Merging #3044 into master will decrease coverage by 0.38%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3044      +/-   ##
==========================================
- Coverage   68.90%   68.52%   -0.39%     
==========================================
  Files         370      370              
  Lines       36401    36401              
==========================================
- Hits        25083    24943     -140     
- Misses       8143     8276     +133     
- Partials     3175     3182       +7     
Impacted Files Coverage Δ
go/oasis-node/cmd/common/metrics/disk.go 65.51% <0.00%> (-20.69%) ⬇️
go/common/badger/helpers.go 63.63% <0.00%> (-18.19%) ⬇️
go/worker/compute/executor/committee/state.go 74.07% <0.00%> (-11.12%) ⬇️
go/consensus/tendermint/apps/scheduler/query.go 71.05% <0.00%> (-7.90%) ⬇️
go/consensus/tendermint/apps/staking/query.go 49.09% <0.00%> (-7.28%) ⬇️
go/storage/metrics.go 75.00% <0.00%> (-6.53%) ⬇️
go/staking/api/grpc.go 53.19% <0.00%> (-5.53%) ⬇️
go/registry/api/grpc.go 35.16% <0.00%> (-4.90%) ⬇️
go/storage/api/root_cache.go 70.11% <0.00%> (-4.60%) ⬇️
go/runtime/tagindexer/tagindexer.go 68.47% <0.00%> (-4.35%) ⬇️
... and 33 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de123b2...669b335. Read the comment docs.

@tjanez tjanez force-pushed the tjanez/e2e-scenarios branch from 546b6c9 to 6786ad0 Compare June 24, 2020 08:56
tjanez added 2 commits June 24, 2020 14:26
List all available scenarios if oasis-test-runner command is invoked
with an unknown scenario.
Previously, Execute() called nodeCommon.EarlyLogAndExit() if there was
an error running rootCmd.Execute() which in turn printed the error to
stderr.
The error message is printed to stdout via github.com/spf13/cobra's
ExecuteC() already, so this resulted in the same error message being
printed twice.
@tjanez tjanez force-pushed the tjanez/e2e-scenarios branch from 6786ad0 to 83a464a Compare June 24, 2020 12:26
Instead, return an ordinary error which is then propagated and printed
to logs accordingly.
@tjanez tjanez force-pushed the tjanez/e2e-scenarios branch from 83a464a to 669b335 Compare June 24, 2020 12:38
@tjanez tjanez merged commit 9dba6d1 into master Jun 24, 2020
@tjanez tjanez deleted the tjanez/e2e-scenarios branch June 24, 2020 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c:cli Category: command line interface c:testing Category: testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants