这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@abdoroot
Copy link
Contributor

@abdoroot abdoroot commented Jul 22, 2024

Fixes #52.

@jesusprubio
Copy link
Owner

Thank you! I would prefer to merge a proper solution instead this workaround.

The problem here is the function newTestHTTPServer returning before the server is listening. Because the call to ListenAndServe is made inside a goroutine:

up/pkg/protocols_test.go

Lines 66 to 67 in 520cd9e

go func() {
err := server.ListenAndServe()

Please check this solution. I think it should work: https://stackoverflow.com/a/53332769

@abdoroot
Copy link
Contributor Author

thanks for suggestion it work

Copy link
Owner

@jesusprubio jesusprubio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Only a couple of formatting changes are we are ready to merge. :)

server := &http.Server{Addr: hostPort}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
mux := http.NewServeMux()
server := &http.Server{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use one line to define server.

Addr: hostPort,
Handler:mux,
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove the empty lines to keep the formatting consistent.

go func() {
err := server.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
if err := server.Serve(l); err != nil && err != http.ErrServerClosed {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use two different lines. Also to keep the formatting consistent with the codebase.

hostPort := net.JoinHostPort("127.0.0.1", "8080")
server := &http.Server{Addr: hostPort}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
mux := http.NewServeMux()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a mux for this simple scenario. The line 63 should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay got it

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :)

@jesusprubio jesusprubio merged commit 4093d58 into jesusprubio:main Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: TestHttpProbe/returns_the_status_code_if_the_request_is_successful

2 participants