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

fix: Better wait in CLI integration test #1415

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions tests/integration/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import (
"github.com/sourcenetwork/defradb/config"
)

const COMMAND_TIMEOUT_SECONDS = 2
const COMMAND_TIMEOUT_SECONDS = 2 * time.Second
const SUBCOMMAND_TIME_BUFFER_SECONDS = 1 * time.Second

type DefraNodeConfig struct {
rootDir string
Expand Down Expand Up @@ -85,18 +86,21 @@ func runDefraNode(t *testing.T, conf DefraNodeConfig) func() []string {

cfg := config.DefaultConfig()
ctx, cancel := context.WithCancel(context.Background())
go func() {
ready := make(chan struct{})
go func(ready chan struct{}) {
defraCmd := cli.NewDefraCommand(cfg)
defraCmd.RootCmd.SetArgs(
append([]string{"start"}, args...),
)
ready <- struct{}{}
err := defraCmd.Execute(ctx)
assert.NoError(t, err)
}()
time.Sleep(1 * time.Second) // time buffer for it to start
}(ready)
<-ready
time.Sleep(SUBCOMMAND_TIME_BUFFER_SECONDS)
cancelAndOutput := func() []string {
cancel()
time.Sleep(1 * time.Second) // time buffer for it to stop
time.Sleep(SUBCOMMAND_TIME_BUFFER_SECONDS)
lines, err := readLoglines(t, conf.logPath)
assert.NoError(t, err)
return lines
Expand All @@ -115,7 +119,7 @@ func runDefraCommand(t *testing.T, conf DefraNodeConfig, args []string) (stdout,
args = append(args, "--rootdir", t.TempDir())
}

ctx, cancel := context.WithTimeout(context.Background(), COMMAND_TIMEOUT_SECONDS*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), COMMAND_TIMEOUT_SECONDS)
defer cancel()

stdout, stderr = captureOutput(func() {
Expand Down