From f6556fce9f2917f7c0db399b3dd54afd8e340bae Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Wed, 19 Nov 2025 15:10:59 +0200 Subject: [PATCH] test(coderd/workspaceapps/apptest): fix lastusedat assertion for all test (#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 --- coderd/workspaceapps/apptest/setup.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/coderd/workspaceapps/apptest/setup.go b/coderd/workspaceapps/apptest/setup.go index 7fef20503b..65eebf8eca 100644 --- a/coderd/workspaceapps/apptest/setup.go +++ b/coderd/workspaceapps/apptest/setup.go @@ -195,6 +195,22 @@ func setupProxyTestWithFactory(t *testing.T, factory DeploymentFactory, opts *De if opts.DisableSubdomainApps { opts.AppHost = "" } + if opts.StatsCollectorOptions.ReportInterval == 0 { + // Set 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. + opts.StatsCollectorOptions.ReportInterval = 9001 * time.Hour + } deployment := factory(t, opts)