-
Notifications
You must be signed in to change notification settings - Fork 93
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
Refactor daemon, add more tests #1039
Refactor daemon, add more tests #1039
Conversation
2ef3652
to
ce855b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start. RIP globals.
Codecov Report
@@ Coverage Diff @@
## localledger/integration #1039 +/- ##
==========================================================
Coverage ? 60.02%
==========================================================
Files ? 49
Lines ? 8731
Branches ? 0
==========================================================
Hits ? 5241
Misses ? 3004
Partials ? 486 Continue to review full report at Codecov.
|
3efd44e
to
b762879
Compare
@winder @AlgoStephenAkiki @shiqizng Should be ready for another round of reviews whenever you all have a chance. :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few suggestions. Overall this is really great.
cmd/algorand-indexer/daemon_test.go
Outdated
if !strings.Contains(err.Error(), errorStr) { | ||
t.Fatalf("expected error %s, but got %s", errorStr, err.Error()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You get the idea, same thing for the rest of these.
if !strings.Contains(err.Error(), errorStr) { | |
t.Fatalf("expected error %s, but got %s", errorStr, err.Error()) | |
} | |
require.Error(t, err) | |
require.Contains(t, err.Error(), errorStr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! It looks like we should be able to write integration tests for daemon after this change.
if indexerDataDir == "" { | ||
fmt.Fprint(os.Stderr, "indexer data directory was not provided") | ||
panic(exit{1}) | ||
func loadIndexerConfig(indexerDataDir string, configFile string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlgoStephenAkiki this function looks correct to me. Is anything needed for the BindFlags still?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would still need to bind the flags yes.
defer configs.Close() | ||
err = viper.ReadConfig(configs) | ||
// Detect the various auto-loading configs from data directory | ||
if err = loadIndexerConfig(daemonConfig.indexerDataDir, daemonConfig.configFile); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlgoStephenAkiki if we move this ahead of the BindFlagSet
call, can we avoid calling that function twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so since the problem is that we have a circular dependency on the logger inside the loadIndexerConfig
function (the logger needs to be configured from configuration and the function uses the logger but also can re-load the configuration).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just want Stephen to double check the config file loading.
logger.WithError(err).Errorf("invalid config file (%s): %v", viper.ConfigFileUsed(), err) | ||
return err | ||
} | ||
logger.Infof("Using configuration file: %s\n", resolvedConfigPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this log statement we should call BindSetFlags() to make sure we get everything set.
* Local Ledger (#1011) * integrate block processor * Local Ledger Deployment (#1013) * add simple local ledger migration * add deleted opts * fast catchup (#1023) * add fast catchup * Localledger merge (#1036) * return empty lists from fetchApplications and fetchAppLocalStates (#1010) * Update model to converge with algod (#1005) * New Feature: Adds Data Directory Support (#1012) - Updates the go-algorand submodule hash to point to rel/beta - Moves the cpu profiling file, pid file and indexer configuration file to be options of only the daemon sub-command - Changes os.Exit() to be a panic with a special handler. This is so that defer's are handled instead of being ignored. - Detects auto-loading configuration files in the data directory and issues errors if equivalent command line arguments are supplied. - Updates the README with instructions on how to use the auto-loading configuration files and the data directory. * Update mockery version Co-authored-by: erer1243 <[email protected]> Co-authored-by: AlgoStephenAkiki <[email protected]> * recovery scenario (#1024) * handle ledger recovery scenario * refactor create genesis block (#1026) * refactor create genesis block * Adds Local Ledger Readme (#1035) * Adds Local Ledger Readme Resolves #4109 Starts Readme docs * Update docs/LocalLedger.md Co-authored-by: Will Winder <[email protected]> * Update docs/LocalLedger.md Co-authored-by: Will Winder <[email protected]> * Update docs/LocalLedger.md Co-authored-by: Will Winder <[email protected]> * Removed troubleshooting section Co-authored-by: Will Winder <[email protected]> * update ledger file path and migration (#1042) * LocalLedger Refactoring + Catchpoint Service (#1049) Part 1 cleanup genesis file access. put node catchup into a function that can be swapped out with the catchup service. pass the indexer logger into the block processor. move open ledger into a util function, and move the initial state util function into a new ledger util file. add initial catchupservice implementation. move ledger init from daemon.go to constructor. Merge multiple read genesis functions. Part 2 Merge local_ledger migration package into blockprocessor. Rename Migration to Initialize Use logger in catchup service catchup Part 3 Update submodule and use NewWrappedLogger. Make util.CreateInitState private * build: merge develop into localledger/integration (#1062) * Ledger init status (#1058) * Generate an error if the catchpoint is not valid for initialization. (#1075) * Use main logger in handler and fetcher. (#1077) * Switch from fullNode catchup to catchpoint catchup service. (#1076) * Refactor daemon, add more tests (#1039) Refactors daemon cmd into separate, testable pieces. * Merge develop into localledger/integration (#1083) * Misc Local Ledger cleanup (#1086) * Update processor/blockprocessor/initialize.go Co-authored-by: Zeph Grunschlag <[email protected]> * commit * fix function call args * RFC-0001: Rfc 0001 impl (#1069) Adds an Exporter interface and a noop exporter implementation with factory methods for construction * Fix test errors * Add/fix tests * Add postgresql_exporter tests * Update config loading * Change BlockExportData to pointers * Move and rename ExportData * Add Empty func to BlockData * Add comment Co-authored-by: shiqizng <[email protected]> Co-authored-by: [email protected] <[email protected]> Co-authored-by: erer1243 <[email protected]> Co-authored-by: AlgoStephenAkiki <[email protected]> Co-authored-by: Will Winder <[email protected]> Co-authored-by: Zeph Grunschlag <[email protected]>
Summary
First in a series which aims to clean up our commands into something more testable and adds coverage.
makeOptions
call inapi_config.go
because it was only being used for a single argument, and I've refactored it to take a config.daemon.go
to a struct,daemonConfig
daemonConfig
, anddaemonCmd
runDaemon
. In the future we can separate this out further into more modular testable pieces, for now I've left it as one giant runner.panic
andos.Exit
calls from this except in the base cobra command. By only passing errors around it becomes more easily testable, we don't have to worry about defer funcs not running which is the reason we have the panic logic, and we are still able to properly exit non-zero when the error reaches the command'sRun
function.makeOptions
has been refactored to convert between adaemonConfig
andapi.ExtraOptions
.BindFlagSet
which is a copy ofBindFlags
since it makes sense to pass theFlagSet
around instead of the command, but I'm not yet able to fully convert the existing function without more changes.Test Plan
Added various tests to get started on testing--mostly for config variables/params for now. It shows how the new setup can be used to simplify tests and validate specific scenarios.