You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using fiber, which uses fasthttp v1.57. I think the recent changes in server.done channel initialization causes the context to always done when writing tests. Considering this example:
package main
import (
"context""io""net/http""github.com/gofiber/fiber/v2"
)
funcmain() {
app:=fiber.New()
app.Get("/", func(c*fiber.Ctx) error {
select {
case<-c.Context().Done():
returnc.JSON("context is done")
default:
returnc.JSON("context is not done")
}
})
req, _:=http.NewRequestWithContext(context.Background(), "GET", "/", nil)
resp, _:=app.Test(req)
deferresp.Body.Close()
body, _:=io.ReadAll(resp.Body)
// Output: should be "context is not done" but it's "context is done"println(string(body))
}
The reason I think is that server.done channel is only initialized when calling server.Serve or when checking context.Done(). Its value is nil when creating a new fasthttp.Server struct, which fiber v2 is doing.
c.Context().Done() will create a new channel (because done is nil) and send an empty message to the channel, which causes the context.Done() to return immediately. (though I'm not sure if this is intentional).
done channel is also not exported so it's impossible to assign it to a channel to avoid this issue. I see there's a fakeServer which init the done channel, but it's also not exported. Is this possible to have a method to init this done channel?
EDIT: this doesn't happen if we run the server and serve real requests because done channel is created when calling server.Serve
The text was updated successfully, but these errors were encountered:
Description
fasthttp
v1.57. I think the recent changes inserver.done
channel initialization causes the context to always done when writing tests. Considering this example:server.done
channel is only initialized when callingserver.Serve
or when checkingcontext.Done()
. Its value is nil when creating a newfasthttp.Server
struct, which fiber v2 is doing.c.Context().Done()
will create a new channel (becausedone
is nil) and send an empty message to the channel, which causes the context.Done() to return immediately. (though I'm not sure if this is intentional).done
channel is also not exported so it's impossible to assign it to a channel to avoid this issue. I see there's afakeServer
which init thedone
channel, but it's also not exported. Is this possible to have a method to init thisdone
channel?EDIT: this doesn't happen if we run the server and serve real requests because
done
channel is created when callingserver.Serve
The text was updated successfully, but these errors were encountered: