Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(coderd): use stable sorting for insights and improve test coverage#9250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 33 commits intomainfrommafredri/test-improve-template-insights-tests
Aug 24, 2023

Conversation

mafredri
Copy link
Member

@mafredrimafredri commentedAug 22, 2023
edited
Loading

This PR introduces a new test suite for insights and makes it easy to add new test scenarios which can then be compared against golden file changes.

A few bugfixes found by the test suite are included as well.

Fixes#9213

@mafredrimafredriforce-pushed themafredri/test-improve-template-insights-tests branch fromb4a50c3 tobd15af7CompareAugust 23, 2023 12:31
@mafredrimafredriforce-pushed themafredri/test-improve-template-insights-tests branch frombd15af7 to73367d1CompareAugust 23, 2023 15:51
@mafredri
Copy link
MemberAuthor

I think this ready now, I might add some more test further down the line but I'd like to start with optimizations next.

@mafredrimafredri marked this pull request as ready for reviewAugust 23, 2023 21:18
Comment on lines +1127 to +1135
// TODO(mafredri): This doesn't behave correctly right now
// and will add more usage to the app. This could be
// considered both correct and incorrect behavior.
// { // One hour of usage, but same user and same template app, only count once.
// app: users[0].workspaces[1].apps[0],
// startedAt: frozenWeekAgo,
// endedAt: frozenWeekAgo.Add(time.Hour),
// requests: 1,
// },
Copy link
MemberAuthor

@mafredrimafredriAug 23, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is something I will fix later on, I wanted to keep query logic changes minimal for now.

Essentially this boils down to:

  • User A has two workspaces in template X
  • User A opens code-server in both workspaces
  • User A closes both code-servers ater an hour
  • We should only show 1h of code-server usage in template X

Currently we show two hours. Motivation for this is that a user can't effectively use multiple code-servers simultaneously. Imagine if this was 10 workspaces, the user would have to have very many skill points in parallel thinking and perhaps get a few extra keyboards and grow some extra limbs to produce 10h of usage in 1h. 😄

mtojek reacted with thumbs up emoji
Copy link
Member

@mtojekmtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Better test coverage is always welcome!

@@ -2480,6 +2489,8 @@ func (q *FakeQuerier) GetTemplateParameterInsights(ctx context.Context, arg data
}
}

// NOTE(mafredri): Add sorting if we decide on how to handle PostgreSQL collations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

out of curiosity: what is the default PostgreSQL behavior considering the "most default" configuration?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It will depend on the systems locale. Essentially if e.g. ifLC_ALL=C orLC_ALL=en_US.UTF-8 is set when callinginitdb, it will produce different results.

@@ -0,0 +1,44 @@
{
"report": {
"start_time": "0001-01-01T00:00:00Z",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

should we populate this with real timestamps? just to prevent UI from breaking down accidentally

johnstcn reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is only for the test and to ensure the golden file isn't updated every day.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, I was rather thinking about the case when somebody forgets to set this field, and a unit test could potentially catch it.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It will be caught by the other tests in this suite 👍🏻.

Withoutdbgen, builds are generated "now", so we must request "now" to check them. But "now" keeps changing and can't be used in the golden file. The other data is fixed-in-time and we can request fixed-in-time so the times get tested that way.

}

// Create the template version and template.
version := coderdtest.CreateTemplateVersion(t, client, firstUser.OrganizationID, &echo.Responses{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

nit: maybe we should depend ondbgen as much as possible to shorten the test execution and prevent potential flakes

johnstcn reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I evaluated doing that, but we didn't have any methods for generating template/workspace build parameters. Perhaps it could be a future improvement?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍

makeRequest func([]*testTemplate) codersdk.TemplateInsightsRequest
ignoreTimes bool
}
tests := []struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Do you think that we can convert-to-table/remove some other insights tests?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think we can delete at least one or two. But depending on if we rely primarily on dbgen here or not, we might want to keep some "whole tests" around.

mtojek reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I deleted one testTestTemplateInsights, its test cases are now covered by the golden files and then some.

johnstcn reacted with thumbs up emoji
@mafredrimafredri changed the titletest(coderd): add extended template insights test suitefix(coderd): use stable sorting for insights and improve test coverageAug 24, 2023
@mafredrimafredri merged commit6b69abf intomainAug 24, 2023
@mafredrimafredri deleted the mafredri/test-improve-template-insights-tests branchAugust 24, 2023 10:36
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsAug 24, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mtojekmtojekmtojek approved these changes

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@mafredrimafredri

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Improve tests for template insights
3 participants
@mafredri@johnstcn@mtojek

[8]ページ先頭

©2009-2025 Movatter.jp