Skip to content

chore: refactor AgentHasNotConnectedSinceWeek_LogsExpired #13802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: refactor AgentHasNotConnectedSinceWeek_LogsExpired
  • Loading branch information
mtojek committed Jul 8, 2024
commit 42f4bffc6fbdb051c74969c99f8be8f169a78bbf
15 changes: 12 additions & 3 deletions coderd/database/dbpurge/dbpurge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
"golang.org/x/exp/slices"
Expand Down Expand Up @@ -183,20 +184,28 @@ func TestDeleteOldWorkspaceAgentLogs(t *testing.T) {
// given
agent := mustCreateAgentWithLogs(ctx, t, db, user, org, tmpl, tv, now.Add(-8*24*time.Hour), t.Name())

// Make sure that agent logs have been collected.
agentLogs, err := db.GetWorkspaceAgentLogsAfter(ctx, database.GetWorkspaceAgentLogsAfterParams{
AgentID: agent,
})
require.NoError(t, err)
require.NotZero(t, agentLogs, "agent logs must be present")

// when
closer := dbpurge.New(ctx, logger, db)
defer closer.Close()

// then
require.Eventually(t, func() bool {
agentLogs, err := db.GetWorkspaceAgentLogsAfter(ctx, database.GetWorkspaceAgentLogsAfterParams{
assert.Eventually(t, func() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert.Eventually(t, func() bool {
require.Eventually(t, func() bool {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require.Eventually will fail with Condition never met. I want to run the follow-up assertion afterward to see what is on the list.

agentLogs, err = db.GetWorkspaceAgentLogsAfter(ctx, database.GetWorkspaceAgentLogsAfterParams{
AgentID: agent,
})
if err != nil {
return false
require.FailNow(t, "unable to get agent logs: %w", err)
}
return !containsAgentLog(agentLogs, t.Name())
}, testutil.WaitShort, testutil.IntervalFast)
require.NotContains(t, agentLogs, t.Name())
})

t.Run("AgentConnectedSixDaysAgo_LogsValid", func(t *testing.T) {
Expand Down
Loading