Skip to content

Commit f6556fc

Browse files
authored
test(coderd/workspaceapps/apptest): fix lastusedat assertion for all test (coder#20827)
The test flake can be verified by setting `ReportInterval` to a really low value, like `100 * time.Millisecond`. We now set it to a really high value to avoid triggering flush without manually calling the function in test. This can easily happen because the default value is 30s and we run tests in parallel. The assertion typically happens such that: [use workspace] -> [fetch previous last used] -> [flush] -> [fetch new last used] When this edge case is triggered: [use workspace] -> [report interval flush] -> [fetch previous last used] -> [flush] -> [fetch new last used] In this case, both the previous and new last used will be the same, breaking the test assertion. Fixes coder/internal#960 Fixes coder/internal#975
1 parent 8e22cd7 commit f6556fc

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎coderd/workspaceapps/apptest/setup.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,22 @@ func setupProxyTestWithFactory(t *testing.T, factory DeploymentFactory, opts *De
195195
if opts.DisableSubdomainApps {
196196
opts.AppHost = ""
197197
}
198+
if opts.StatsCollectorOptions.ReportInterval == 0 {
199+
// Set to a really high value to avoid triggering flush without manually
200+
// calling the function in test. This can easily happen because the
201+
// default value is 30s and we run tests in parallel. The assertion
202+
// typically happens such that:
203+
//
204+
// [use workspace] -> [fetch previous last used] -> [flush] -> [fetch new last used]
205+
//
206+
// When this edge case is triggered:
207+
//
208+
// [use workspace] -> [report interval flush] -> [fetch previous last used] -> [flush] -> [fetch new last used]
209+
//
210+
// In this case, both the previous and new last used will be the same,
211+
// breaking the test assertion.
212+
opts.StatsCollectorOptions.ReportInterval = 9001 * time.Hour
213+
}
198214

199215
deployment := factory(t, opts)
200216

0 commit comments

Comments
 (0)