MCPcopy Index your code
hub / github.com/coder/coder / TestWorkspaceProxyDERPMeshProbe

Function TestWorkspaceProxyDERPMeshProbe

enterprise/wsproxy/wsproxy_test.go:547–866  ·  view source on GitHub ↗

TestWorkspaceProxyDERPMeshProbe ensures that each replica pings every other replica in the same region as itself periodically.

(t *testing.T)

Source from the content-addressed store, hash-verified

545// TestWorkspaceProxyDERPMeshProbe ensures that each replica pings every other
546// replica in the same region as itself periodically.
547func TestWorkspaceProxyDERPMeshProbe(t *testing.T) {
548 t.Parallel()
549 createProxyRegion := func(ctx context.Context, t *testing.T, client *codersdk.Client, name string) codersdk.UpdateWorkspaceProxyResponse {
550 t.Helper()
551 proxyRes, err := client.CreateWorkspaceProxy(ctx, codersdk.CreateWorkspaceProxyRequest{
552 Name: name,
553 Icon: "/emojis/flag.png",
554 })
555 require.NoError(t, err, "failed to create workspace proxy")
556 return proxyRes
557 }
558
559 registerBrokenProxy := func(ctx context.Context, t *testing.T, primaryAccessURL *url.URL, accessURL, token string) uuid.UUID {
560 t.Helper()
561 // Create a HTTP server that always replies with 500.
562 srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
563 rw.WriteHeader(http.StatusInternalServerError)
564 }))
565 t.Cleanup(srv.Close)
566
567 // Register a proxy.
568 wsproxyClient := wsproxysdk.New(primaryAccessURL, token)
569 hostname, err := cryptorand.String(6)
570 require.NoError(t, err)
571 replicaID := uuid.New()
572 _, err = wsproxyClient.RegisterWorkspaceProxy(ctx, wsproxysdk.RegisterWorkspaceProxyRequest{
573 AccessURL: accessURL,
574 WildcardHostname: "",
575 DerpEnabled: true,
576 DerpOnly: false,
577 ReplicaID: replicaID,
578 ReplicaHostname: hostname,
579 ReplicaError: "",
580 ReplicaRelayAddress: srv.URL,
581 Version: buildinfo.Version(),
582 })
583 require.NoError(t, err)
584
585 return replicaID
586 }
587
588 t.Run("ProbeOK", func(t *testing.T) {
589 t.Parallel()
590
591 deploymentValues := coderdtest.DeploymentValues(t)
592 deploymentValues.Experiments = []string{
593 "*",
594 }
595
596 client, closer, api, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
597 Options: &coderdtest.Options{
598 DeploymentValues: deploymentValues,
599 AppHostname: "*.primary.test.coder.com",
600 IncludeProvisionerDaemon: true,
601 RealIPConfig: &httpmw.RealIPConfig{
602 TrustedOrigins: []*net.IPNet{{
603 IP: net.ParseIP("127.0.0.1"),
604 Mask: net.CIDRMask(8, 32),

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
StringFunction · 0.92
VersionFunction · 0.92
DeploymentValuesFunction · 0.92
NewWithAPIFunction · 0.92
ContextFunction · 0.92
NewWorkspaceProxyReplicaFunction · 0.92
TryReceiveFunction · 0.92
createProxyReplicasFunction · 0.85
CreateWorkspaceProxyMethod · 0.80
NotEmptyMethod · 0.80
LogMethod · 0.80

Tested by

no test coverage detected