mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: user status change chart accommodates DST (#22191)
closes https://github.com/coder/internal/issues/464 # Summary This PR resolves a flaky test that was sensitive to DST transitions in various time zones. The root of the flake was: * a bug; the query and its tests assume 24 hours per day * the tests used local system time, which resulted in failures for dates proximal to DST transitions # Changes Query: The original query assumed 24 hour intervals between each day, which is not a valid assumption. It now increments `1 day` at a time. Database tests: Database level tests for the query all assumed 24 hour days. They now increment in DST-aware days instead. Instead of using time.Now() as a base for testing, the test uses a series of dates over the course of an entire year, to ensure that DST transition dates are present in every test run. # API Endpoint The endpoint that delivers the user status chart now accepts an IANA timezone name as a parameter and passes it, keeping the existing offset as a fallback, to the database query. API level tests were added to ensure the correct response form and error behaviour. Correctness of content is tested at the database level.
This commit is contained in:
+5
-2
@@ -2533,11 +2533,14 @@ class ApiMethods {
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// Intl.DateTimeFormat().resolvedOptions().timeZone returns an IANA timezone
|
||||
// name (e.g. "America/New_York") per ECMA-402. Go's time.LoadLocation and
|
||||
// PostgreSQL's timezone() both accept IANA names, so these are compatible.
|
||||
getInsightsUserStatusCounts = async (
|
||||
offset = Math.trunc(new Date().getTimezoneOffset() / 60),
|
||||
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
): Promise<TypesGen.GetUserStatusCountsResponse> => {
|
||||
const searchParams = new URLSearchParams({
|
||||
tz_offset: offset.toString(),
|
||||
timezone,
|
||||
});
|
||||
const response = await this.axios.get(
|
||||
`/api/v2/insights/user-status-counts?${searchParams}`,
|
||||
|
||||
Generated
+3
-3
@@ -2838,11 +2838,11 @@ export interface GetInboxNotificationResponse {
|
||||
|
||||
// From codersdk/insights.go
|
||||
export interface GetUserStatusCountsRequest {
|
||||
readonly timezone: string;
|
||||
/**
|
||||
* Timezone offset in hours. Use 0 for UTC, and TimezoneOffsetHour(time.Local)
|
||||
* for the local timezone.
|
||||
* Deprecated: Use Timezone instead. Offset is ignored when Timezone is provided.
|
||||
*/
|
||||
readonly offset: number;
|
||||
readonly offset?: number;
|
||||
}
|
||||
|
||||
// From codersdk/insights.go
|
||||
|
||||
Reference in New Issue
Block a user