Skip to content

Commit 5df66d7

Browse files
committed
review
1 parent 2f71aaa commit 5df66d7

File tree

1 file changed

+7
-28
lines changed

1 file changed

+7
-28
lines changed

coderd/metricscache/metricscache_test.go

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ func TestCache_TemplateWorkspaceOwners(t *testing.T) {
6161

6262
cache, db := newMetricsCache(t, log, clock, metricscache.Intervals{
6363
TemplateBuildTimes: time.Minute,
64-
DeploymentStats: time.Minute,
6564
}, false)
6665

6766
org := dbgen.Organization(t, db, database.Organization{})
@@ -77,10 +76,7 @@ func TestCache_TemplateWorkspaceOwners(t *testing.T) {
7776
trapTickerFunc.MustWait(ctx).MustRelease(ctx)
7877
trapTickerFunc.MustWait(ctx).MustRelease(ctx)
7978

80-
_, wait := clock.AdvanceNext()
81-
wait.MustWait(ctx)
82-
_, wait = clock.AdvanceNext()
83-
wait.MustWait(ctx)
79+
clock.Advance(time.Minute).MustWait(ctx)
8480

8581
count, ok := cache.TemplateWorkspaceOwners(template.ID)
8682
require.True(t, ok, "TemplateWorkspaceOwners should be populated")
@@ -92,10 +88,7 @@ func TestCache_TemplateWorkspaceOwners(t *testing.T) {
9288
OwnerID: user1.ID,
9389
})
9490

95-
_, wait = clock.AdvanceNext()
96-
wait.MustWait(ctx)
97-
_, wait = clock.AdvanceNext()
98-
wait.MustWait(ctx)
91+
clock.Advance(time.Minute).MustWait(ctx)
9992

10093
count, _ = cache.TemplateWorkspaceOwners(template.ID)
10194
require.Equal(t, 1, count, "should have 1 owner after adding workspace")
@@ -106,10 +99,7 @@ func TestCache_TemplateWorkspaceOwners(t *testing.T) {
10699
OwnerID: user2.ID,
107100
})
108101

109-
_, wait = clock.AdvanceNext()
110-
wait.MustWait(ctx)
111-
_, wait = clock.AdvanceNext()
112-
wait.MustWait(ctx)
102+
clock.Advance(time.Minute).MustWait(ctx)
113103

114104
count, _ = cache.TemplateWorkspaceOwners(template.ID)
115105
require.Equal(t, 2, count, "should have 2 owners after adding second workspace")
@@ -126,10 +116,7 @@ func TestCache_TemplateWorkspaceOwners(t *testing.T) {
126116
Deleted: true,
127117
})
128118

129-
_, wait = clock.AdvanceNext()
130-
wait.MustWait(ctx)
131-
_, wait = clock.AdvanceNext()
132-
wait.MustWait(ctx)
119+
clock.Advance(time.Minute).MustWait(ctx)
133120

134121
count, _ = cache.TemplateWorkspaceOwners(template.ID)
135122
require.Equal(t, 1, count, "should have 1 owner after deleting workspace")
@@ -233,7 +220,6 @@ func TestCache_BuildTime(t *testing.T) {
233220
defer trapTickerFunc.Close()
234221
cache, db := newMetricsCache(t, log, clock, metricscache.Intervals{
235222
TemplateBuildTimes: time.Minute,
236-
DeploymentStats: time.Minute,
237223
}, false)
238224

239225
org := dbgen.Organization(t, db, database.Organization{})
@@ -282,10 +268,7 @@ func TestCache_BuildTime(t *testing.T) {
282268
trapTickerFunc.MustWait(ctx).MustRelease(ctx)
283269
trapTickerFunc.MustWait(ctx).MustRelease(ctx)
284270

285-
_, wait := clock.AdvanceNext()
286-
wait.MustWait(ctx)
287-
_, wait = clock.AdvanceNext()
288-
wait.MustWait(ctx)
271+
clock.Advance(time.Minute).MustWait(ctx)
289272

290273
if tt.want.loads {
291274
wantTransition := codersdk.WorkspaceTransition(tt.args.transition)
@@ -322,8 +305,7 @@ func TestCache_DeploymentStats(t *testing.T) {
322305
defer tickerTrap.Close()
323306

324307
cache, db := newMetricsCache(t, log, clock, metricscache.Intervals{
325-
TemplateBuildTimes: time.Minute,
326-
DeploymentStats: time.Minute,
308+
DeploymentStats: time.Minute,
327309
}, false)
328310

329311
err := db.InsertWorkspaceAgentStats(context.Background(), database.InsertWorkspaceAgentStatsParams{
@@ -353,10 +335,7 @@ func TestCache_DeploymentStats(t *testing.T) {
353335
tickerTrap.MustWait(ctx).MustRelease(ctx)
354336
tickerTrap.MustWait(ctx).MustRelease(ctx)
355337

356-
_, wait := clock.AdvanceNext()
357-
wait.MustWait(ctx)
358-
_, wait = clock.AdvanceNext()
359-
wait.MustWait(ctx)
338+
clock.Advance(time.Minute).MustWait(ctx)
360339

361340
stat, ok := cache.DeploymentStats()
362341
require.True(t, ok, "cache should be populated after refresh")

0 commit comments

Comments
 (0)