-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include block-generator and validator as algorand-indexer subcommands. (
#891)
- Loading branch information
Showing
9 changed files
with
291 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package core | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/algorand/indexer/cmd/block-generator/generator" | ||
"github.com/algorand/indexer/cmd/block-generator/runner" | ||
) | ||
|
||
// BlockGenerator related cobra commands, ready to be executed or included as subcommands. | ||
var BlockGenerator *cobra.Command | ||
|
||
func init() { | ||
BlockGenerator = &cobra.Command{ | ||
Use: `block-generator`, | ||
Short: `Block generator testing tools.`, | ||
} | ||
BlockGenerator.AddCommand(runner.RunnerCmd) | ||
BlockGenerator.AddCommand(generator.DaemonCmd) | ||
} |
19 changes: 9 additions & 10 deletions
19
cmd/block-generator/daemon.go → cmd/block-generator/generator/daemon.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,33 @@ | ||
package main | ||
package generator | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/algorand/indexer/cmd/block-generator/generator" | ||
) | ||
|
||
// DaemonCmd starts a block generator daemon. | ||
var DaemonCmd *cobra.Command | ||
|
||
func init() { | ||
rand.Seed(12345) | ||
|
||
var configFile string | ||
var port uint64 | ||
|
||
var daemonCmd = &cobra.Command{ | ||
DaemonCmd = &cobra.Command{ | ||
Use: "daemon", | ||
Short: "Start the generator daemon in standalone mode.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
addr := fmt.Sprintf(":%d", port) | ||
srv, _ := generator.MakeServer(configFile, addr) | ||
srv, _ := MakeServer(configFile, addr) | ||
srv.ListenAndServe() | ||
}, | ||
} | ||
|
||
daemonCmd.Flags().StringVarP(&configFile, "config", "c", "", "Specify the block configuration yaml file.") | ||
daemonCmd.Flags().Uint64VarP(&port, "port", "p", 4010, "Port to start the server at.") | ||
|
||
daemonCmd.MarkFlagRequired("config") | ||
DaemonCmd.Flags().StringVarP(&configFile, "config", "c", "", "Specify the block configuration yaml file.") | ||
DaemonCmd.Flags().Uint64VarP(&port, "port", "p", 4010, "Port to start the server at.") | ||
|
||
rootCmd.AddCommand(daemonCmd) | ||
DaemonCmd.MarkFlagRequired("config") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
package main | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: `block-generator`, | ||
Short: `Block generator testing tools.`, | ||
} | ||
import "github.com/algorand/indexer/cmd/block-generator/core" | ||
|
||
func main() { | ||
rootCmd.Execute() | ||
core.BlockGenerator.Execute() | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package runner | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// RunnerCmd launches the block-generator test suite runner. | ||
var RunnerCmd *cobra.Command | ||
|
||
func init() { | ||
rand.Seed(12345) | ||
var runnerArgs Args | ||
|
||
RunnerCmd = &cobra.Command{ | ||
Use: "runner", | ||
Short: "Run test suite and collect results.", | ||
Long: "Run an automated test suite using the block-generator daemon and a provided algorand-indexer binary. Results are captured to a specified output directory.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := Run(runnerArgs); err != nil { | ||
fmt.Println(err) | ||
} | ||
}, | ||
} | ||
|
||
RunnerCmd.Flags().StringVarP(&runnerArgs.Path, "scenario", "s", "", "Directory containing scenarios, or specific scenario file.") | ||
RunnerCmd.Flags().StringVarP(&runnerArgs.IndexerBinary, "indexer-binary", "i", "", "Path to indexer binary.") | ||
RunnerCmd.Flags().Uint64VarP(&runnerArgs.IndexerPort, "indexer-port", "p", 4010, "Port to start the server at. This is useful if you have a prometheus server for collecting additional data.") | ||
RunnerCmd.Flags().StringVarP(&runnerArgs.PostgresConnectionString, "postgres-connection-string", "c", "", "Postgres connection string.") | ||
RunnerCmd.Flags().DurationVarP(&runnerArgs.RunDuration, "test-duration", "d", 5*time.Minute, "Duration to use for each scenario.") | ||
RunnerCmd.Flags().StringVarP(&runnerArgs.ReportDirectory, "report-directory", "r", "", "Location to place test reports.") | ||
RunnerCmd.Flags().StringVarP(&runnerArgs.LogLevel, "log-level", "l", "error", "LogLevel to use when starting Indexer. [error, warn, info, debug, trace]") | ||
RunnerCmd.Flags().StringVarP(&runnerArgs.CPUProfilePath, "cpuprofile", "", "", "Path where Indexer writes its CPU profile.") | ||
RunnerCmd.Flags().BoolVarP(&runnerArgs.ResetReportDir, "reset", "", false, "If set any existing report directory will be deleted before running tests.") | ||
RunnerCmd.Flags().BoolVarP(&runnerArgs.RunValidation, "validate", "", false, "If set the validator will run after test-duration has elapsed to verify data is correct. An extra line in each report indicates validator success or failure.") | ||
|
||
RunnerCmd.MarkFlagRequired("scenario") | ||
RunnerCmd.MarkFlagRequired("indexer-binary") | ||
RunnerCmd.MarkFlagRequired("postgres-connection-string") | ||
RunnerCmd.MarkFlagRequired("report-directory") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.