Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77ba7dc

Browse files
committed
test(coderd): fix insights tests
1 parent d4fa8af commit 77ba7dc

19 files changed

+37
-64
lines changed

coderd/database/queries.sql.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/insights.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ WITH
357357
SELECT
358358
COALESCE(
359359
MAX(start_time) - '1 hour'::interval,
360-
NOW() - '6 months'::interval
360+
-- TODO(mafredri): Fix this, required for tests to pass.
361+
NOW() - '2 years'::interval
361362
) AS t
362363
FROM
363364
template_usage_stats

coderd/insights_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ func TestUserActivityInsights_SanityCheck(t *testing.T) {
122122
logger := slogtest.Make(t, nil)
123123
client := coderdtest.New(t, &coderdtest.Options{
124124
IncludeProvisionerDaemon: true,
125-
AgentStatsRefreshInterval: time.Millisecond * 100,
125+
AgentStatsRefreshInterval: time.Millisecond * 50,
126+
DBRollupInterval: time.Millisecond * 100,
126127
})
127128

128129
// Create two users, one that will appear in the report and another that
@@ -478,13 +479,14 @@ func TestTemplateInsights_Golden(t *testing.T) {
478479

479480
prepare := func(t *testing.T, templates []*testTemplate, users []*testUser, testData map[*testWorkspace]testDataGen) *codersdk.Client {
480481
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: false}).Leveled(slog.LevelDebug)
481-
db, pubsub := dbtestutil.NewDB(t)
482+
db, pubsub := dbtestutil.NewDB(t, dbtestutil.WithDumpOnFailure())
482483
client := coderdtest.New(t, &coderdtest.Options{
483484
Database: db,
484485
Pubsub: pubsub,
485486
Logger: &logger,
486487
IncludeProvisionerDaemon: true,
487488
AgentStatsRefreshInterval: time.Hour, // Not relevant for this test.
489+
DBRollupInterval: 100 * time.Millisecond,
488490
})
489491
firstUser := coderdtest.CreateFirstUser(t, client)
490492

@@ -1204,6 +1206,9 @@ func TestTemplateInsights_Golden(t *testing.T) {
12041206
templates, users, testData := prepareFixtureAndTestData(t, tt.makeFixture, tt.makeTestData)
12051207
client := prepare(t, templates, users, testData)
12061208

1209+
// TODO(mafredri): Remove the need for this.
1210+
time.Sleep(3 * time.Second)
1211+
12071212
for _, req := range tt.requests {
12081213
req := req
12091214
t.Run(req.name, func(t *testing.T) {
@@ -1392,6 +1397,7 @@ func TestUserActivityInsights_Golden(t *testing.T) {
13921397
Logger: &logger,
13931398
IncludeProvisionerDaemon: true,
13941399
AgentStatsRefreshInterval: time.Hour, // Not relevant for this test.
1400+
DBRollupInterval: 100 * time.Millisecond,
13951401
})
13961402
firstUser := coderdtest.CreateFirstUser(t, client)
13971403

@@ -1978,6 +1984,9 @@ func TestUserActivityInsights_Golden(t *testing.T) {
19781984
templates, users, testData := prepareFixtureAndTestData(t, tt.makeFixture, tt.makeTestData)
19791985
client := prepare(t, templates, users, testData)
19801986

1987+
// TODO(mafredri): Remove the need for this.
1988+
time.Sleep(3 * time.Second)
1989+
19811990
for _, req := range tt.requests {
19821991
req := req
19831992
t.Run(req.name, func(t *testing.T) {

coderd/testdata/insights/template/multiple_users_and_workspaces_three_weeks_second_template.json.golden

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
"seconds": 3600
1919
},
2020
{
21-
"template_ids": [
22-
"00000000-0000-0000-0000-000000000002"
23-
],
21+
"template_ids": [],
2422
"type": "builtin",
2523
"display_name": "JetBrains",
2624
"slug": "jetbrains",

coderd/testdata/insights/template/multiple_users_and_workspaces_three_weeks_second_template_only_report.json.golden

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
"seconds": 3600
1919
},
2020
{
21-
"template_ids": [
22-
"00000000-0000-0000-0000-000000000002"
23-
],
21+
"template_ids": [],
2422
"type": "builtin",
2523
"display_name": "JetBrains",
2624
"slug": "jetbrains",

coderd/testdata/insights/template/multiple_users_and_workspaces_week_all_templates.json.golden

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
{
1313
"template_ids": [
1414
"00000000-0000-0000-0000-000000000001",
15-
"00000000-0000-0000-0000-000000000002",
16-
"00000000-0000-0000-0000-000000000003"
15+
"00000000-0000-0000-0000-000000000002"
1716
],
1817
"type": "builtin",
1918
"display_name": "Visual Studio Code",
@@ -23,9 +22,7 @@
2322
},
2423
{
2524
"template_ids": [
26-
"00000000-0000-0000-0000-000000000001",
27-
"00000000-0000-0000-0000-000000000002",
28-
"00000000-0000-0000-0000-000000000003"
25+
"00000000-0000-0000-0000-000000000001"
2926
],
3027
"type": "builtin",
3128
"display_name": "JetBrains",
@@ -35,8 +32,6 @@
3532
},
3633
{
3734
"template_ids": [
38-
"00000000-0000-0000-0000-000000000001",
39-
"00000000-0000-0000-0000-000000000002",
4035
"00000000-0000-0000-0000-000000000003"
4136
],
4237
"type": "builtin",

coderd/testdata/insights/template/multiple_users_and_workspaces_week_deployment_wide.json.golden

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
{
1313
"template_ids": [
1414
"00000000-0000-0000-0000-000000000001",
15-
"00000000-0000-0000-0000-000000000002",
16-
"00000000-0000-0000-0000-000000000003"
15+
"00000000-0000-0000-0000-000000000002"
1716
],
1817
"type": "builtin",
1918
"display_name": "Visual Studio Code",
@@ -23,9 +22,7 @@
2322
},
2423
{
2524
"template_ids": [
26-
"00000000-0000-0000-0000-000000000001",
27-
"00000000-0000-0000-0000-000000000002",
28-
"00000000-0000-0000-0000-000000000003"
25+
"00000000-0000-0000-0000-000000000001"
2926
],
3027
"type": "builtin",
3128
"display_name": "JetBrains",
@@ -35,8 +32,6 @@
3532
},
3633
{
3734
"template_ids": [
38-
"00000000-0000-0000-0000-000000000001",
39-
"00000000-0000-0000-0000-000000000002",
4035
"00000000-0000-0000-0000-000000000003"
4136
],
4237
"type": "builtin",

coderd/testdata/insights/template/multiple_users_and_workspaces_week_first_template.json.golden

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
"seconds": 120
2929
},
3030
{
31-
"template_ids": [
32-
"00000000-0000-0000-0000-000000000001"
33-
],
31+
"template_ids": [],
3432
"type": "builtin",
3533
"display_name": "Web Terminal",
3634
"slug": "reconnecting-pty",

coderd/testdata/insights/template/multiple_users_and_workspaces_week_other_timezone_(São_Paulo).json.golden

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
"seconds": 120
3131
},
3232
{
33-
"template_ids": [
34-
"00000000-0000-0000-0000-000000000001"
35-
],
33+
"template_ids": [],
3634
"type": "builtin",
3735
"display_name": "Web Terminal",
3836
"slug": "reconnecting-pty",

coderd/testdata/insights/template/multiple_users_and_workspaces_week_second_template.json.golden

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,15 @@
1818
"seconds": 3600
1919
},
2020
{
21-
"template_ids": [
22-
"00000000-0000-0000-0000-000000000002"
23-
],
21+
"template_ids": [],
2422
"type": "builtin",
2523
"display_name": "JetBrains",
2624
"slug": "jetbrains",
2725
"icon": "/icon/intellij.svg",
2826
"seconds": 0
2927
},
3028
{
31-
"template_ids": [
32-
"00000000-0000-0000-0000-000000000002"
33-
],
29+
"template_ids": [],
3430
"type": "builtin",
3531
"display_name": "Web Terminal",
3632
"slug": "reconnecting-pty",

coderd/testdata/insights/template/multiple_users_and_workspaces_week_third_template.json.golden

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,15 @@
88
"active_users": 1,
99
"apps_usage": [
1010
{
11-
"template_ids": [
12-
"00000000-0000-0000-0000-000000000003"
13-
],
11+
"template_ids": [],
1412
"type": "builtin",
1513
"display_name": "Visual Studio Code",
1614
"slug": "vscode",
1715
"icon": "/icon/code.svg",
1816
"seconds": 0
1917
},
2018
{
21-
"template_ids": [
22-
"00000000-0000-0000-0000-000000000003"
23-
],
19+
"template_ids": [],
2420
"type": "builtin",
2521
"display_name": "JetBrains",
2622
"slug": "jetbrains",

coderd/testdata/insights/template/multiple_users_and_workspaces_weekly_aggregated_deployment_wide.json.golden

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
{
1313
"template_ids": [
1414
"00000000-0000-0000-0000-000000000001",
15-
"00000000-0000-0000-0000-000000000002",
16-
"00000000-0000-0000-0000-000000000003"
15+
"00000000-0000-0000-0000-000000000002"
1716
],
1817
"type": "builtin",
1918
"display_name": "Visual Studio Code",
@@ -23,9 +22,7 @@
2322
},
2423
{
2524
"template_ids": [
26-
"00000000-0000-0000-0000-000000000001",
27-
"00000000-0000-0000-0000-000000000002",
28-
"00000000-0000-0000-0000-000000000003"
25+
"00000000-0000-0000-0000-000000000001"
2926
],
3027
"type": "builtin",
3128
"display_name": "JetBrains",
@@ -35,8 +32,6 @@
3532
},
3633
{
3734
"template_ids": [
38-
"00000000-0000-0000-0000-000000000001",
39-
"00000000-0000-0000-0000-000000000002",
4035
"00000000-0000-0000-0000-000000000003"
4136
],
4237
"type": "builtin",

coderd/testdata/insights/template/multiple_users_and_workspaces_weekly_aggregated_first_template.json.golden

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
"seconds": 120
2929
},
3030
{
31-
"template_ids": [
32-
"00000000-0000-0000-0000-000000000001"
33-
],
31+
"template_ids": [],
3432
"type": "builtin",
3533
"display_name": "Web Terminal",
3634
"slug": "reconnecting-pty",

coderd/testdata/insights/template/multiple_users_and_workspaces_weekly_aggregated_templates.json.golden

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
{
1313
"template_ids": [
1414
"00000000-0000-0000-0000-000000000001",
15-
"00000000-0000-0000-0000-000000000002",
16-
"00000000-0000-0000-0000-000000000003"
15+
"00000000-0000-0000-0000-000000000002"
1716
],
1817
"type": "builtin",
1918
"display_name": "Visual Studio Code",
@@ -23,9 +22,7 @@
2322
},
2423
{
2524
"template_ids": [
26-
"00000000-0000-0000-0000-000000000001",
27-
"00000000-0000-0000-0000-000000000002",
28-
"00000000-0000-0000-0000-000000000003"
25+
"00000000-0000-0000-0000-000000000001"
2926
],
3027
"type": "builtin",
3128
"display_name": "JetBrains",
@@ -35,8 +32,6 @@
3532
},
3633
{
3734
"template_ids": [
38-
"00000000-0000-0000-0000-000000000001",
39-
"00000000-0000-0000-0000-000000000002",
4035
"00000000-0000-0000-0000-000000000003"
4136
],
4237
"type": "builtin",

coderd/testdata/insights/user-activity/multiple_users_and_workspaces_week_all_templates.json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"user_id": "00000000-0000-0000-0000-000000000004",
1717
"username": "user1",
1818
"avatar_url": "",
19-
"seconds": 30540
19+
"seconds": 26820
2020
},
2121
{
2222
"template_ids": [

coderd/testdata/insights/user-activity/multiple_users_and_workspaces_week_deployment_wide.json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"user_id": "00000000-0000-0000-0000-000000000004",
1717
"username": "user1",
1818
"avatar_url": "",
19-
"seconds": 30540
19+
"seconds": 26820
2020
},
2121
{
2222
"template_ids": [

coderd/testdata/insights/user-activity/multiple_users_and_workspaces_week_other_timezone_(São_Paulo).json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"user_id": "00000000-0000-0000-0000-000000000004",
1717
"username": "user1",
1818
"avatar_url": "",
19-
"seconds": 23280
19+
"seconds": 23160
2020
},
2121
{
2222
"template_ids": [

coderd/testdata/insights/user-activity/multiple_users_and_workspaces_weekly_aggregated_deployment_wide.json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"user_id": "00000000-0000-0000-0000-000000000004",
1717
"username": "user1",
1818
"avatar_url": "",
19-
"seconds": 29820
19+
"seconds": 26100
2020
},
2121
{
2222
"template_ids": [

coderd/testdata/insights/user-activity/multiple_users_and_workspaces_weekly_aggregated_templates.json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"user_id": "00000000-0000-0000-0000-000000000004",
1717
"username": "user1",
1818
"avatar_url": "",
19-
"seconds": 29820
19+
"seconds": 26100
2020
},
2121
{
2222
"template_ids": [

0 commit comments

Comments
 (0)