fix: resolve flakey inbox tests (#17010)

This commit is contained in:
Danielle Maywood
2025-03-19 22:06:47 +00:00
committed by GitHub
parent 4ea5ef925f
commit b39477c07a
2 changed files with 26 additions and 20 deletions

View File

@ -94,18 +94,6 @@ func (api *API) watchInboxNotifications(rw http.ResponseWriter, r *http.Request)
return
}
conn, err := websocket.Accept(rw, r, nil)
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Failed to upgrade connection to websocket.",
Detail: err.Error(),
})
return
}
go httpapi.Heartbeat(ctx, conn)
defer conn.Close(websocket.StatusNormalClosure, "connection closed")
notificationCh := make(chan codersdk.InboxNotification, 10)
closeInboxNotificationsSubscriber, err := api.Pubsub.SubscribeWithErr(pubsub.InboxNotificationForOwnerEventChannel(apikey.UserID),
@ -161,9 +149,20 @@ func (api *API) watchInboxNotifications(rw http.ResponseWriter, r *http.Request)
api.Logger.Error(ctx, "subscribe to inbox notification event", slog.Error(err))
return
}
defer closeInboxNotificationsSubscriber()
conn, err := websocket.Accept(rw, r, nil)
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Failed to upgrade connection to websocket.",
Detail: err.Error(),
})
return
}
go httpapi.Heartbeat(ctx, conn)
defer conn.Close(websocket.StatusNormalClosure, "connection closed")
encoder := wsjson.NewEncoder[codersdk.GetInboxNotificationResponse](conn, websocket.MessageText)
defer encoder.Close(websocket.StatusNormalClosure)