-
Notifications
You must be signed in to change notification settings - Fork 116
add signal interrupt to local network contexts #2717
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
Changes from all commits
ee66f5e
bc1d829
f650fe3
15c0613
2e450b9
8cb7786
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |
| package localnet | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
|
|
||
|
|
@@ -78,6 +80,19 @@ func TrackSubnet( | |
| perNodeBlockchainConfig, | ||
| wallet, | ||
| ); err != nil { | ||
| if errors.Is(err, context.DeadlineExceeded) { | ||
| printFunc("") | ||
| printFunc("A context timeout has occurred while trying to bootstrap the blockchain.") | ||
| printFunc("") | ||
| logPaths, _ := GetTmpNetAvailableLogs(networkDir, blockchainID, false) | ||
| if len(logPaths) != 0 { | ||
| printFunc("Please check this log files for more information on the error cause:") | ||
| for _, logPath := range logPaths { | ||
| printFunc(" " + logPath) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add unit test for helpers_test.go where we intentionally cause error and verify that we get the expected logs dir
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added test for GetTmpNetAvailableLogs |
||
| } | ||
| printFunc("") | ||
| } | ||
| } | ||
| return err | ||
| } | ||
| ux.Logger.GreenCheckmarkToUser("%s successfully tracking %s", networkModel.Name(), blockchainName) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| // Copyright (C) 2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
| package localnet | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/ava-labs/avalanche-cli/pkg/application" | ||
| "github.com/ava-labs/avalanche-cli/pkg/config" | ||
| "github.com/ava-labs/avalanche-cli/pkg/constants" | ||
| "github.com/ava-labs/avalanche-cli/pkg/prompts" | ||
| "github.com/ava-labs/avalanchego/ids" | ||
| "github.com/ava-labs/avalanchego/utils/logging" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func createFile(t *testing.T, path string) { | ||
| f, err := os.Create(path) | ||
| require.NoError(t, err) | ||
| err = f.Close() | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| func TestGetTmpNetAvailableLogs(t *testing.T) { | ||
| app := &application.Avalanche{} | ||
| appDir, err := os.MkdirTemp(os.TempDir(), "cli-app-test") | ||
| require.NoError(t, err) | ||
| app.Setup(appDir, logging.NoLog{}, config.New(), "", prompts.NewPrompter(), application.NewDownloader(), nil) | ||
| networkID, unparsedGenesis, upgradeBytes, defaultFlags, nodes, err := GetDefaultNetworkConf(2) | ||
| require.NoError(t, err) | ||
| networkDir, err := os.MkdirTemp(os.TempDir(), "cli-tmpnet-test") | ||
| require.NoError(t, err) | ||
| _, err = TmpNetCreate( | ||
| context.Background(), | ||
| app.Log, | ||
| networkDir, | ||
| "", | ||
| "", | ||
| networkID, | ||
| nil, | ||
| nil, | ||
| unparsedGenesis, | ||
| upgradeBytes, | ||
| defaultFlags, | ||
| nodes, | ||
| false, | ||
| ) | ||
| require.NoError(t, err) | ||
| // no logs yet | ||
| logPaths, err := GetTmpNetAvailableLogs(networkDir, ids.Empty, false) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []string{}, logPaths) | ||
| // default network | ||
| node1ID := "NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg" | ||
| node2ID := "NodeID-MFrZFVCXPv5iCn6M9K6XduxGTYp891xXZ" | ||
| node1Logs := filepath.Join(networkDir, node1ID, "logs") | ||
| node2Logs := filepath.Join(networkDir, node2ID, "logs") | ||
| err = os.MkdirAll(node1Logs, constants.DefaultPerms755) | ||
| require.NoError(t, err) | ||
| err = os.MkdirAll(node2Logs, constants.DefaultPerms755) | ||
| require.NoError(t, err) | ||
| // add main log | ||
| createFile(t, filepath.Join(node1Logs, "main.log")) | ||
| createFile(t, filepath.Join(node2Logs, "main.log")) | ||
| logPaths, err = GetTmpNetAvailableLogs(networkDir, ids.Empty, false) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []string{ | ||
| filepath.Join(node1Logs, "main.log"), | ||
| filepath.Join(node2Logs, "main.log"), | ||
| }, logPaths) | ||
| // add P chain log | ||
| createFile(t, filepath.Join(node1Logs, "P.log")) | ||
| createFile(t, filepath.Join(node2Logs, "P.log")) | ||
| logPaths, err = GetTmpNetAvailableLogs(networkDir, ids.Empty, false) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []string{ | ||
| filepath.Join(node1Logs, "P.log"), | ||
| filepath.Join(node1Logs, "main.log"), | ||
| filepath.Join(node2Logs, "P.log"), | ||
| filepath.Join(node2Logs, "main.log"), | ||
| }, logPaths) | ||
| // gather C chain when no files are present | ||
| logPaths, err = GetTmpNetAvailableLogs(networkDir, ids.Empty, true) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []string{ | ||
| filepath.Join(node1Logs, "P.log"), | ||
| filepath.Join(node1Logs, "main.log"), | ||
| filepath.Join(node2Logs, "P.log"), | ||
| filepath.Join(node2Logs, "main.log"), | ||
| }, logPaths) | ||
| // gather C chain when files are present | ||
| createFile(t, filepath.Join(node1Logs, "C.log")) | ||
| createFile(t, filepath.Join(node2Logs, "C.log")) | ||
| logPaths, err = GetTmpNetAvailableLogs(networkDir, ids.Empty, true) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []string{ | ||
| filepath.Join(node1Logs, "C.log"), | ||
| filepath.Join(node1Logs, "P.log"), | ||
| filepath.Join(node1Logs, "main.log"), | ||
| filepath.Join(node2Logs, "C.log"), | ||
| filepath.Join(node2Logs, "P.log"), | ||
| filepath.Join(node2Logs, "main.log"), | ||
| }, logPaths) | ||
| // don't gather C chain when files are present | ||
| logPaths, err = GetTmpNetAvailableLogs(networkDir, ids.Empty, false) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []string{ | ||
| filepath.Join(node1Logs, "P.log"), | ||
| filepath.Join(node1Logs, "main.log"), | ||
| filepath.Join(node2Logs, "P.log"), | ||
| filepath.Join(node2Logs, "main.log"), | ||
| }, logPaths) | ||
| // gather blockchain when no files are present | ||
| blockchainID := ids.GenerateTestID() | ||
| logPaths, err = GetTmpNetAvailableLogs(networkDir, blockchainID, false) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []string{ | ||
| filepath.Join(node1Logs, "P.log"), | ||
| filepath.Join(node1Logs, "main.log"), | ||
| filepath.Join(node2Logs, "P.log"), | ||
| filepath.Join(node2Logs, "main.log"), | ||
| }, logPaths) | ||
| // gather blockchain when files are present | ||
| createFile(t, filepath.Join(node1Logs, blockchainID.String()+".log")) | ||
| createFile(t, filepath.Join(node2Logs, blockchainID.String()+".log")) | ||
| logPaths, err = GetTmpNetAvailableLogs(networkDir, blockchainID, false) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []string{ | ||
| filepath.Join(node1Logs, blockchainID.String()+".log"), | ||
| filepath.Join(node1Logs, "P.log"), | ||
| filepath.Join(node1Logs, "main.log"), | ||
| filepath.Join(node2Logs, blockchainID.String()+".log"), | ||
| filepath.Join(node2Logs, "P.log"), | ||
| filepath.Join(node2Logs, "main.log"), | ||
| }, logPaths) | ||
| // don't gather blockchain when files are present | ||
| logPaths, err = GetTmpNetAvailableLogs(networkDir, ids.Empty, false) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []string{ | ||
| filepath.Join(node1Logs, "P.log"), | ||
| filepath.Join(node1Logs, "main.log"), | ||
| filepath.Join(node2Logs, "P.log"), | ||
| filepath.Join(node2Logs, "main.log"), | ||
| }, logPaths) | ||
| // gather all files are present | ||
| logPaths, err = GetTmpNetAvailableLogs(networkDir, blockchainID, true) | ||
| require.NoError(t, err) | ||
| require.Equal(t, []string{ | ||
| filepath.Join(node1Logs, blockchainID.String()+".log"), | ||
| filepath.Join(node1Logs, "C.log"), | ||
| filepath.Join(node1Logs, "P.log"), | ||
| filepath.Join(node1Logs, "main.log"), | ||
| filepath.Join(node2Logs, blockchainID.String()+".log"), | ||
| filepath.Join(node2Logs, "C.log"), | ||
| filepath.Join(node2Logs, "P.log"), | ||
| filepath.Join(node2Logs, "main.log"), | ||
| }, logPaths) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.