|
7 | 7 | "net/http/httputil"
|
8 | 8 | "net/url"
|
9 | 9 | "testing"
|
| 10 | + "time" |
10 | 11 |
|
11 | 12 | "github.com/google/uuid"
|
12 | 13 | "github.com/moby/moby/pkg/namesgenerator"
|
@@ -172,6 +173,69 @@ func TestRegions(t *testing.T) {
|
172 | 173 | require.Error(t, err)
|
173 | 174 | require.Empty(t, regions)
|
174 | 175 | })
|
| 176 | + |
| 177 | + t.Run("GoingAway", func(t *testing.T) { |
| 178 | + t.Parallel() |
| 179 | + |
| 180 | + dv := coderdtest.DeploymentValues(t) |
| 181 | + dv.Experiments = []string{ |
| 182 | + string(codersdk.ExperimentMoons), |
| 183 | + "*", |
| 184 | + } |
| 185 | + |
| 186 | + db, pubsub := dbtestutil.NewDB(t) |
| 187 | + |
| 188 | + ctx := testutil.Context(t, testutil.WaitLong) |
| 189 | + |
| 190 | + client, closer, api := coderdenttest.NewWithAPI(t, &coderdenttest.Options{ |
| 191 | + Options: &coderdtest.Options{ |
| 192 | + AppHostname: appHostname, |
| 193 | + Database: db, |
| 194 | + Pubsub: pubsub, |
| 195 | + DeploymentValues: dv, |
| 196 | + }, |
| 197 | + // The interval is set to 1 hour so the proxy health |
| 198 | + // check will never happen manually. All checks will be |
| 199 | + // forced updates. |
| 200 | + ProxyHealthInterval: time.Hour, |
| 201 | + }) |
| 202 | + t.Cleanup(func() { |
| 203 | + _ = closer.Close() |
| 204 | + }) |
| 205 | + _ = coderdtest.CreateFirstUser(t, client) |
| 206 | + _ = coderdenttest.AddLicense(t, client, coderdenttest.LicenseOptions{ |
| 207 | + Features: license.Features{ |
| 208 | + codersdk.FeatureWorkspaceProxy: 1, |
| 209 | + }, |
| 210 | + }) |
| 211 | + |
| 212 | + const proxyName = "testproxy" |
| 213 | + proxy := coderdenttest.NewWorkspaceProxy(t, api, client, &coderdenttest.ProxyOptions{ |
| 214 | + Name: proxyName, |
| 215 | + }) |
| 216 | + _ = proxy |
| 217 | + |
| 218 | + require.Eventuallyf(t, func() bool { |
| 219 | + proxy, err := client.WorkspaceProxyByName(ctx, proxyName) |
| 220 | + if err != nil { |
| 221 | + // We are testing the going away, not the initial healthy. |
| 222 | + // Just force an update to change this to healthy. |
| 223 | + _ = api.ProxyHealth.ForceUpdate(ctx) |
| 224 | + return false |
| 225 | + } |
| 226 | + return proxy.Status.Status == codersdk.ProxyHealthy |
| 227 | + }, testutil.WaitShort, testutil.IntervalFast, "proxy never became healthy") |
| 228 | + |
| 229 | + _ = proxy.Close() |
| 230 | + // The proxy should tell the primary on close that is is no longer healthy. |
| 231 | + require.Eventuallyf(t, func() bool { |
| 232 | + proxy, err := client.WorkspaceProxyByName(ctx, proxyName) |
| 233 | + if err != nil { |
| 234 | + return false |
| 235 | + } |
| 236 | + return proxy.Status.Status == codersdk.ProxyUnhealthy |
| 237 | + }, testutil.WaitShort, testutil.IntervalFast, "proxy never became unhealthy after close") |
| 238 | + }) |
175 | 239 | }
|
176 | 240 |
|
177 | 241 | func TestWorkspaceProxyCRUD(t *testing.T) {
|
|
0 commit comments