(t *testing.T)
| 2552 | } |
| 2553 | |
| 2554 | func TestWorkspaceAgent_Metadata_CatchMemoryLeak(t *testing.T) { |
| 2555 | t.Parallel() |
| 2556 | |
| 2557 | store, psub := dbtestutil.NewDB(t) |
| 2558 | db := &testWAMErrorStore{Store: store} |
| 2559 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Named("coderd").Leveled(slog.LevelDebug) |
| 2560 | client := coderdtest.New(t, &coderdtest.Options{ |
| 2561 | Database: db, |
| 2562 | Pubsub: psub, |
| 2563 | IncludeProvisionerDaemon: true, |
| 2564 | Logger: &logger, |
| 2565 | }) |
| 2566 | user := coderdtest.CreateFirstUser(t, client) |
| 2567 | r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 2568 | OrganizationID: user.OrganizationID, |
| 2569 | OwnerID: user.UserID, |
| 2570 | }).WithAgent(func(agents []*proto.Agent) []*proto.Agent { |
| 2571 | agents[0].Metadata = []*proto.Agent_Metadata{ |
| 2572 | { |
| 2573 | DisplayName: "First Meta", |
| 2574 | Key: "foo1", |
| 2575 | Script: "echo hi", |
| 2576 | Interval: 10, |
| 2577 | Timeout: 3, |
| 2578 | }, |
| 2579 | { |
| 2580 | DisplayName: "Second Meta", |
| 2581 | Key: "foo2", |
| 2582 | Script: "echo bye", |
| 2583 | Interval: 10, |
| 2584 | Timeout: 3, |
| 2585 | }, |
| 2586 | } |
| 2587 | return agents |
| 2588 | }).Do() |
| 2589 | workspace, err := client.Workspace(context.Background(), r.Workspace.ID) |
| 2590 | require.NoError(t, err) |
| 2591 | for _, res := range workspace.LatestBuild.Resources { |
| 2592 | for _, a := range res.Agents { |
| 2593 | require.Equal(t, codersdk.WorkspaceAgentLifecycleCreated, a.LifecycleState) |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | agentClient := agentsdk.New(client.URL, agentsdk.WithFixedToken(r.AgentToken)) |
| 2598 | |
| 2599 | ctx := testutil.Context(t, testutil.WaitSuperLong) |
| 2600 | conn, err := agentClient.ConnectRPC(ctx) |
| 2601 | require.NoError(t, err) |
| 2602 | defer func() { |
| 2603 | cErr := conn.Close() |
| 2604 | require.NoError(t, cErr) |
| 2605 | }() |
| 2606 | aAPI := agentproto.NewDRPCAgentClient(conn) |
| 2607 | |
| 2608 | manifest := requireGetManifest(ctx, t, aAPI) |
| 2609 | |
| 2610 | post := func(ctx context.Context, key, value string) error { |
| 2611 | _, err := aAPI.BatchUpdateMetadata(ctx, &agentproto.BatchUpdateMetadataRequest{ |
nothing calls this directly
no test coverage detected