-
-
Notifications
You must be signed in to change notification settings - Fork 380
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
feat: make docker compose startup time configurable #1166
Conversation
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
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.
Thank you and congratulations 🎉 for opening your very first pull request in keploy
I have read the CLA Document and I hereby sign the CLA |
Apply Sweep Rules to your PR?
|
cmd/record.go
Outdated
@@ -206,6 +221,8 @@ func (r *Record) GetCmd() *cobra.Command { | |||
|
|||
recordCmd.Flags().Uint64P("delay", "d", 5, "User provided time to run its application") | |||
|
|||
recordCmd.Flags().Uint64P("buildDelay", "", 30, "User provided time to wait docker container build") |
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.
time would be a better datatype for inputting delay. Some docker builds can take minutes to startup. You can input it like that using Duration. Please make sure to change it everywhere. You can refer this: https://pkg.go.dev/time
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.
got it, thanks. I will change it latter 😃
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.
time would be a better datatype for inputting delay. Some docker builds can take minutes to startup. You can input it like that using Duration. Please make sure to change it everywhere. You can refer this: https://pkg.go.dev/time
Hey @EraKin575 , I want to set the type of buildDelay to string
, so that we can use time.ParseDuration
to parse the build time input by the user, such as "30s", "5m". Do you think this is a better idea than changing the type of buildDelay from uint64
to duration
?
The string type is only used to process user input. After initialization, the buildDelay variable will use the time.Duration type to participate in parameter transfer, time judgment and recording configuration.
I made a mistake, in fact, Flags#GetDuration
automatically parses the time expression entered by the user like 30s
, I mistakenly thought that it only accepts numeric type input. The modification has been completed, thank you for your help !
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 won't be able to configure time like '30m5s'. Even if you do, that would be unnecessary complexity into this
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 won't be able to configure time like '30m5s'. Even if you do, that would be unnecessary complexity into this
That's right, I'll go ahead and set the buildDelay type to time.Duration and specify the parameter's default unit to be seconds. Then I'll modify the relevant directive help
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
Please update the screenshot too |
cmd/serve.go
Outdated
@@ -66,6 +67,13 @@ func (s *Serve) GetCmd() *cobra.Command { | |||
return | |||
} | |||
|
|||
buildDelay, err := cmd.Flags().GetDuration("buildDelay") |
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.
Right now, buildDelay is only limited to record and test command, please make the required changes.
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.
@IllTamer Can we also use minute time unit in this flag? If yes please add an example of that also.
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.
Sure, I will complete and modify later
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
cmd/test.go
Outdated
@@ -229,6 +239,15 @@ func (t *Test) GetCmd() *cobra.Command { | |||
} | |||
} | |||
|
|||
if buildDelay <= time.Duration(30)*time.Second { |
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.
The same if check should be in the record command as well. And don't mention the example usage of record in the test command. It should be in the record command.
cmd/test.go
Outdated
fmt.Printf("Warning: buildDelay is set to %d, incase your docker container takes more time to build use --buildDelay to set custom delay\n", buildDelay) | ||
if isDockerCmd { | ||
fmt.Println("Example usage:\n", `keploy test -c "docker run -p 8080:808 --network myNetworkName myApplicationImageName" --buildDelay 35s\n`, "\nor\n", `keploy test -c "docker run -p 8080:808 --network myNetworkName myApplicationImageName" --buildDelay 1m\n`) | ||
} else { |
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.
Only mention test command usage here. And the port forwarding in the docker command should have port -p 8080:8080
, please fix this if any other place also has this incorrect port.
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.
Sorry for the confusion, what does 'Only mention test command usage here. ' mean , Shall I remove the warning message 🤔
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.
Sorry, I didn't notice. You don't need to remove the command or any warning message. Just fix the port forwarding.
pkg/service/serve/serve.go
Outdated
@@ -43,7 +43,7 @@ func NewServer(logger *zap.Logger) Server { | |||
const defaultPort = 6789 | |||
|
|||
// Serve is called by the serve command and is used to run a graphql server, to run tests separately via apis. | |||
func (s *server) Serve(path string, proxyPort uint32, testReportPath string, Delay uint64, pid, port uint32, lang string, passThroughPorts []uint, apiTimeout uint64, appCmd string) { | |||
func (s *server) Serve(path string, proxyPort uint32, testReportPath string, Delay uint64, BuildDelay time.Duration, pid, port uint32, lang string, passThroughPorts []uint, apiTimeout uint64, appCmd string) { |
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.
Please remove buildDelay
flag from serve command, Because right not serve command is not supported for docker env.
@@ -61,7 +62,7 @@ func (r *mutationResolver) RunTestSet(ctx context.Context, testSet string) (*mod | |||
go func() { | |||
defer utils.HandlePanic() | |||
r.Logger.Debug("starting testrun...", zap.Any("testSet", testSet)) | |||
tester.RunTestSet(testSet, testCasePath, testReportPath, "", "", "", delay, pid, ys, loadedHooks, testReportFS, testRunChan, r.ApiTimeout, ctx, nil, serveTest) | |||
tester.RunTestSet(testSet, testCasePath, testReportPath, "", "", "", delay, buildDelay, pid, ys, loadedHooks, testReportFS, testRunChan, r.ApiTimeout, ctx, nil, serveTest) |
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 pass some default value for buildDelay
. Anyway, it will not be used in case of serve command. Because if it is a serve command then we don't even start the application by ourselves.
@IllTamer Please address the updated comments & also please update the template of the config file as well. |
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
cmd/serve.go
Outdated
@@ -66,6 +65,11 @@ func (s *Serve) GetCmd() *cobra.Command { | |||
return | |||
} | |||
|
|||
if 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.
You can remove this code since there is no build-delay in the serve command. So no need to check for this error.
} | ||
|
||
if buildDelay <= 30*time.Second { | ||
fmt.Printf("Warning: buildDelay is set to %d, incase your docker container takes more time to build use --buildDelay to set custom delay\n", buildDelay) |
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 warning should be printed only when there is docker command because we don't need the build-delay flag in case of native integration.
@IllTamer Please address the updated comments & resolve the merger conflicts, the rest looks good. And can I use a value like |
@IllTamer can you pease resolve the issues and update the PR! |
There are some things that are delaying me. I will update as soon as possible. : ) |
Yes, you can. It depends on the |
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
cmd/test.go
Outdated
|
||
if isDockerCmd && buildDelay <= 30*time.Second { | ||
fmt.Printf("Warning: buildDelay is set to %d, incase your docker container takes more time to build use --buildDelay to set custom delay\n", buildDelay) | ||
if isDockerCmd { |
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.
No need to check for isDockerCmd
again.
cmd/test.go
Outdated
if isDockerCmd && buildDelay <= 30*time.Second { | ||
fmt.Printf("Warning: buildDelay is set to %d, incase your docker container takes more time to build use --buildDelay to set custom delay\n", buildDelay) | ||
if isDockerCmd { | ||
fmt.Println("Example usage:\n", `keploy test -c "docker-compose up --build" --buildDelay 35s\n`, "\nor\n", `keploy test -c "docker-compose up --build" --buildDelay 1m\n`) | ||
} else { | ||
fmt.Println("Example usage:\n", cmd.Example) |
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.
Since this buildDelay
flag is only in the case of the docker command, there is no need to add this example here.
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.
Since this
buildDelay
flag is only in the case of the docker command, there is no need to add this example here.
By default, do we assume that the docker environment is built when the user uses the record
command? Do we consider the situation where the user needs to rebuild when running the test
command? Then the buildDelay parameter still needs to be checked
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.
@IllTamer Whenever there is a docker env the isDockerCmd
is true since the keploy Dockerfile contains this as an environment variable. So if you've checked that it is dockerCmd & the buildDelay is <=30 then just show the warning as the usage rather than showing another example.
@IllTamer Please resolve the merge conflicts and address the updated comments. |
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
@IllTamer Please resolve the merger conflicts. |
cmd/record.go
Outdated
@@ -172,6 +182,15 @@ func (r *Record) GetCmd() *cobra.Command { | |||
// user provided the absolute path | |||
} | |||
|
|||
if buildDelay <= 30*time.Second { |
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.
Please remove the other example here also. And have you tested your changes with the config file as well?
@IllTamer The build is failing, please fix that. |
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
Signed-off-by: IllTamer <78360471+IllTamer@users.noreply.github.com>
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.
🚀
Related Issue
Closes: #1065
Describe the changes you've made
Make docker compose startup time configurable for
record
,test
andserve
Type of change
Please let us know if any test cases are added
Please describe the tests(if any). Provide instructions how its affecting the coverage.
Describe if there is any unusual behaviour of your code(Write
NA
if there isn't)A clear and concise description of it.
Checklist:
Screenshots (if any)