From 6e8c027d683ac4d489ee96e4ee1eeedfff40281f Mon Sep 17 00:00:00 2001 From: b00ris Date: Tue, 14 Jul 2020 04:56:29 +0300 Subject: [PATCH] fix go run for integration (#741) --- cmd/integration/{ => commands}/flags.go | 2 +- .../{ => commands}/refetence_db.go | 2 +- cmd/integration/{ => commands}/reset_state.go | 2 +- cmd/integration/commands/root.go | 55 +++++++++++++++++++ cmd/integration/{ => commands}/stages.go | 2 +- .../{ => commands}/state_stages.go | 2 +- cmd/integration/main.go | 52 +----------------- 7 files changed, 62 insertions(+), 55 deletions(-) rename cmd/integration/{ => commands}/flags.go (98%) rename cmd/integration/{ => commands}/refetence_db.go (99%) rename cmd/integration/{ => commands}/reset_state.go (99%) create mode 100644 cmd/integration/commands/root.go rename cmd/integration/{ => commands}/stages.go (99%) rename cmd/integration/{ => commands}/state_stages.go (99%) diff --git a/cmd/integration/flags.go b/cmd/integration/commands/flags.go similarity index 98% rename from cmd/integration/flags.go rename to cmd/integration/commands/flags.go index 6bd6deebb..c017725e3 100644 --- a/cmd/integration/flags.go +++ b/cmd/integration/commands/flags.go @@ -1,4 +1,4 @@ -package main +package commands import "github.com/spf13/cobra" diff --git a/cmd/integration/refetence_db.go b/cmd/integration/commands/refetence_db.go similarity index 99% rename from cmd/integration/refetence_db.go rename to cmd/integration/commands/refetence_db.go index f41544588..73f3682ee 100644 --- a/cmd/integration/refetence_db.go +++ b/cmd/integration/commands/refetence_db.go @@ -1,4 +1,4 @@ -package main +package commands import ( "bytes" diff --git a/cmd/integration/reset_state.go b/cmd/integration/commands/reset_state.go similarity index 99% rename from cmd/integration/reset_state.go rename to cmd/integration/commands/reset_state.go index 77befa3fc..d17280dc0 100644 --- a/cmd/integration/reset_state.go +++ b/cmd/integration/commands/reset_state.go @@ -1,4 +1,4 @@ -package main +package commands import ( "context" diff --git a/cmd/integration/commands/root.go b/cmd/integration/commands/root.go new file mode 100644 index 000000000..579e3192d --- /dev/null +++ b/cmd/integration/commands/root.go @@ -0,0 +1,55 @@ +package commands + +import ( + "context" + "fmt" + "github.com/ledgerwatch/turbo-geth/cmd/utils" + "github.com/ledgerwatch/turbo-geth/internal/debug" + "github.com/ledgerwatch/turbo-geth/log" + "github.com/spf13/cobra" + "os" + "os/signal" + "syscall" +) + +var rootCmd = &cobra.Command{ + Use: "integration", + Short: "long and heavy integration tests for turbo-geth", + PersistentPreRun: func(cmd *cobra.Command, args []string) { + if err := debug.SetupCobra(cmd); err != nil { + panic(err) + } + }, + PersistentPostRun: func(cmd *cobra.Command, args []string) { + debug.Exit() + }, +} + +func init() { + utils.CobraFlags(rootCmd, append(debug.Flags, utils.MetricsEnabledFlag, utils.MetricsEnabledExpensiveFlag)) +} + +func rootContext() context.Context { + ctx, cancel := context.WithCancel(context.Background()) + go func() { + ch := make(chan os.Signal, 1) + signal.Notify(ch, os.Interrupt, syscall.SIGTERM) + defer signal.Stop(ch) + + select { + case <-ch: + log.Info("Got interrupt, shutting down...") + case <-ctx.Done(): + } + + cancel() + }() + return ctx +} + +func Execute() { + if err := rootCmd.ExecuteContext(rootContext()); err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/cmd/integration/stages.go b/cmd/integration/commands/stages.go similarity index 99% rename from cmd/integration/stages.go rename to cmd/integration/commands/stages.go index a258244b4..97eac62c9 100644 --- a/cmd/integration/stages.go +++ b/cmd/integration/commands/stages.go @@ -1,4 +1,4 @@ -package main +package commands import ( "context" diff --git a/cmd/integration/state_stages.go b/cmd/integration/commands/state_stages.go similarity index 99% rename from cmd/integration/state_stages.go rename to cmd/integration/commands/state_stages.go index d134669e5..a7cd94d62 100644 --- a/cmd/integration/state_stages.go +++ b/cmd/integration/commands/state_stages.go @@ -1,4 +1,4 @@ -package main +package commands import ( "bytes" diff --git a/cmd/integration/main.go b/cmd/integration/main.go index 6e8ffa1f2..a2979c353 100644 --- a/cmd/integration/main.go +++ b/cmd/integration/main.go @@ -1,56 +1,8 @@ package main -import ( - "context" - "fmt" - "os" - "os/signal" - "syscall" - - "github.com/ledgerwatch/turbo-geth/cmd/utils" - "github.com/ledgerwatch/turbo-geth/internal/debug" - "github.com/ledgerwatch/turbo-geth/log" - "github.com/spf13/cobra" -) - -var rootCmd = &cobra.Command{ - Use: "integration", - Short: "long and heavy integration tests for turbo-geth", - PersistentPreRun: func(cmd *cobra.Command, args []string) { - if err := debug.SetupCobra(cmd); err != nil { - panic(err) - } - }, - PersistentPostRun: func(cmd *cobra.Command, args []string) { - debug.Exit() - }, -} - -func init() { - utils.CobraFlags(rootCmd, append(debug.Flags, utils.MetricsEnabledFlag, utils.MetricsEnabledExpensiveFlag)) -} +import "github.com/ledgerwatch/turbo-geth/cmd/integration/commands" func main() { - if err := rootCmd.ExecuteContext(rootContext()); err != nil { - fmt.Println(err) - os.Exit(1) - } + commands.Execute() } -func rootContext() context.Context { - ctx, cancel := context.WithCancel(context.Background()) - go func() { - ch := make(chan os.Signal, 1) - signal.Notify(ch, os.Interrupt, syscall.SIGTERM) - defer signal.Stop(ch) - - select { - case <-ch: - log.Info("Got interrupt, shutting down...") - case <-ctx.Done(): - } - - cancel() - }() - return ctx -}