TestWorkspaceProxyDERPMeshProbe ensures that each replica pings every other replica in the same region as itself periodically.
(t *testing.T)
| 545 | // TestWorkspaceProxyDERPMeshProbe ensures that each replica pings every other |
| 546 | // replica in the same region as itself periodically. |
| 547 | func 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), |
nothing calls this directly
no test coverage detected