Skip to content

feat: add dbfake for workspace builds and resources #10426

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 2, 2023
Merged

feat: add dbfake for workspace builds and resources #10426

merged 10 commits into from
Nov 2, 2023

Conversation

kylecarbs
Copy link
Member

@kylecarbs kylecarbs commented Oct 30, 2023

This creates coderdtest.NewWithDatabase and adds a series of helper functions to dbfake that insert structured fake data for resources into the database.

It allows us to remove provisionerd from many tests, which should speed them up and reduce flakes.

Ideally, we merge this then I convert all tests to use this new structure. It's intentionally abstract right now because I assume more patterns will emerge as I work through cases.

@kylecarbs kylecarbs requested review from mafredri and Emyrk October 30, 2023 15:37
@kylecarbs kylecarbs self-assigned this Oct 30, 2023
@kylecarbs kylecarbs force-pushed the fakebuild branch 3 times, most recently from 0913ae1 to a6fe665 Compare October 30, 2023 17:16
This creates `coderdtest.NewWithDatabase` and adds a series of
helper functions to `dbfake` that insert structured fake data
for resources into the database.

It allows us to remove provisionerd from a significant amount of
tests which should speed them up and reduce flakes.
@kylecarbs kylecarbs changed the title feat: add dbfakedata for workspace builds and resources feat: add dbfake for workspace builds and resources Oct 30, 2023
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

I like the helper functions. It would be great if we could make another AquireProvisionerJob function to mark jobs as complete. Just mutate the job fields with some "test only" query we have.

Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

Last comment, can merge without. Maybe we should not name this CreateWorkspace, because we use that exact wording in our API related helpers which actually goes through the Create flow and has all the deps correct.

Maybe name it InsertWorkspace? PutWorkspace? Some other word?

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Nice work, I think this is a huge improvement for writing tests!

I did notice CI is still quite unhappy:

        	            	  - pq: insert or update on table "workspace_builds" violates foreign key constraint "workspace_builds_job_id_fkey"

Perhaps just a case of missing ID in a call to dbgen (in dbfake).

@kylecarbs kylecarbs merged commit 839a16e into main Nov 2, 2023
@kylecarbs kylecarbs deleted the fakebuild branch November 2, 2023 17:15
@github-actions github-actions bot locked and limited conversation to collaborators Nov 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants