MCPcopy Create free account
hub / github.com/coder/coder / dialNotificationWebsocket

Method dialNotificationWebsocket

scaletest/notifications/run.go:212–238  ·  view source on GitHub ↗
(ctx context.Context, client *codersdk.Client, logger slog.Logger)

Source from the content-addressed store, hash-verified

210}
211
212func (r *Runner) dialNotificationWebsocket(ctx context.Context, client *codersdk.Client, logger slog.Logger) (*websocket.Conn, error) {
213 u, err := client.URL.Parse("/api/v2/notifications/inbox/watch")
214 if err != nil {
215 logger.Error(ctx, "parse notification URL", slog.Error(err))
216 r.cfg.Metrics.AddError("parse_url")
217 return nil, xerrors.Errorf("parse notification URL: %w", err)
218 }
219
220 conn, resp, err := websocket.Dial(ctx, u.String(), &websocket.DialOptions{
221 HTTPHeader: http.Header{
222 "Coder-Session-Token": []string{client.SessionToken()},
223 },
224 })
225 if err != nil {
226 if resp != nil {
227 defer resp.Body.Close()
228 if resp.StatusCode != http.StatusSwitchingProtocols {
229 err = codersdk.ReadBodyAsError(resp)
230 }
231 }
232 logger.Error(ctx, "dial notification websocket", slog.Error(err))
233 r.cfg.Metrics.AddError("dial")
234 return nil, xerrors.Errorf("dial notification websocket: %w", err)
235 }
236
237 return conn, nil
238}
239
240// watchNotifications reads notifications from the websocket and returns error or nil
241// once all expected notifications are received.

Callers 1

RunMethod · 0.95

Calls 9

ReadBodyAsErrorFunction · 0.92
ParseMethod · 0.65
AddErrorMethod · 0.65
DialMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45
ErrorfMethod · 0.45
StringMethod · 0.45
SessionTokenMethod · 0.45

Tested by

no test coverage detected