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

Function TestWorkspaceAgentAppHealth

coderd/workspaceagents_test.go:2075–2169  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2073}
2074
2075func TestWorkspaceAgentAppHealth(t *testing.T) {
2076 t.Parallel()
2077 client, db := coderdtest.NewWithDatabase(t, nil)
2078 user := coderdtest.CreateFirstUser(t, client)
2079 apps := []*proto.App{
2080 {
2081 Slug: "code-server",
2082 Command: "some-command",
2083 Url: "http://localhost:3000",
2084 Icon: "/code.svg",
2085 },
2086 {
2087 Slug: "code-server-2",
2088 DisplayName: "code-server-2",
2089 Command: "some-command",
2090 Url: "http://localhost:3000",
2091 Icon: "/code.svg",
2092 Healthcheck: &proto.Healthcheck{
2093 Url: "http://localhost:3000",
2094 Interval: 5,
2095 Threshold: 6,
2096 },
2097 },
2098 }
2099 r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
2100 OrganizationID: user.OrganizationID,
2101 OwnerID: user.UserID,
2102 }).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
2103 agents[0].Apps = apps
2104 return agents
2105 }).Do()
2106
2107 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
2108 defer cancel()
2109
2110 agentClient := agentsdk.New(client.URL, agentsdk.WithFixedToken(r.AgentToken))
2111 conn, err := agentClient.ConnectRPC(ctx)
2112 require.NoError(t, err)
2113 defer func() {
2114 cErr := conn.Close()
2115 require.NoError(t, cErr)
2116 }()
2117 aAPI := agentproto.NewDRPCAgentClient(conn)
2118
2119 manifest := requireGetManifest(ctx, t, aAPI)
2120 require.EqualValues(t, codersdk.WorkspaceAppHealthDisabled, manifest.Apps[0].Health)
2121 require.EqualValues(t, codersdk.WorkspaceAppHealthInitializing, manifest.Apps[1].Health)
2122 // empty
2123 _, err = aAPI.BatchUpdateAppHealths(ctx, &agentproto.BatchUpdateAppHealthRequest{})
2124 require.NoError(t, err)
2125 // healthcheck disabled
2126 _, err = aAPI.BatchUpdateAppHealths(ctx, &agentproto.BatchUpdateAppHealthRequest{
2127 Updates: []*agentproto.BatchUpdateAppHealthRequest_HealthUpdate{
2128 {
2129 Id: manifest.Apps[0].ID[:],
2130 Health: agentproto.AppHealth_INITIALIZING,
2131 },
2132 },

Callers

nothing calls this directly

Calls 12

BatchUpdateAppHealthsMethod · 0.95
NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
WorkspaceBuildFunction · 0.92
NewFunction · 0.92
WithFixedTokenFunction · 0.92
requireGetManifestFunction · 0.85
WithAgentMethod · 0.80
ConnectRPCMethod · 0.80
DoMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected