-
Notifications
You must be signed in to change notification settings - Fork 291
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
#931 breaks re-running lifecycle hooks #945
Comments
@abhinav I realize that app start per-request is a pretty common approach in Golang Test |
@zenthangplus Apologies, I didn't mean that to suggest you were doing anything incorrectly. To facilitate this, our service scaffolding system generates something like this: func App() fx.Option {
return fx.Options(
fx.Provide(...),
// ...
)
}
func main() {
fx.New(App()).Run()
} And then inside tests, we do, app := fxtest.New(t, App())
defer app.RequireStart().RequireStop() However, I realize others may not be following this pattern. Would you mind sharing more about how you're structuring your tests and calling App.Start repeatedly so we can better understand this use case? |
@abhinav i'm discussing about integration test for rest api service (i've other case for worker service, more complexity, we will discuss later). about your example, how do you send test request to your api service app. I guess that you need to know the endpoint of your test app (eg: http://localhost:8080/...). In my case, i don't want to send test request over network because we have so many tests, and it will take too long time. So my solution is using a mocked http client to trigger Here is how that solution work: Inside main app:
Then inside test app, i initialize
Then inside every tests i will using mocked http client to call http request to test app:
|
Exactly. The test starts the app listening on a local port and we send requests to the local port. The test server and client need to agree on the port. You can start the server on a dynamic port, use It could look something like this:
|
I know this, but this is my mean:
|
In #931, we added checks to ensure that lifecycle hooks only run once to avoid users accidentally running app.Stop twice by doing: app.Run, app.Stop.
This seems to have broken some users like @zenthangplus, who are re-running app.Start per-request.
Before it works well, but after this MR #931
app.Start
is only allow to run once. I can change my logic to handleapp.Stop
before handle another request but i think this is breaking change and it break my test logic.(again, it not related to this MR)
Originally posted by @zenthangplus in #941 (comment)
The text was updated successfully, but these errors were encountered: