MCPcopy Index your code
hub / github.com/coder/coder / TestWorkspaceSerialization

Function TestWorkspaceSerialization

enterprise/coderd/workspacequota_test.go:705–1177  ·  view source on GitHub ↗

nolint:paralleltest,tparallel // Tests must run serially

(t *testing.T)

Source from the content-addressed store, hash-verified

703
704// nolint:paralleltest,tparallel // Tests must run serially
705func TestWorkspaceSerialization(t *testing.T) {
706 t.Parallel()
707
708 db, _ := dbtestutil.NewDB(t)
709
710 user := dbgen.User(t, db, database.User{})
711 otherUser := dbgen.User(t, db, database.User{})
712
713 org := dbfake.Organization(t, db).
714 EveryoneAllowance(20).
715 Members(user, otherUser).
716 Group(database.Group{
717 QuotaAllowance: 10,
718 }, user, otherUser).
719 Group(database.Group{
720 QuotaAllowance: 10,
721 }, user).
722 Do()
723
724 otherOrg := dbfake.Organization(t, db).
725 EveryoneAllowance(20).
726 Members(user, otherUser).
727 Group(database.Group{
728 QuotaAllowance: 10,
729 }, user, otherUser).
730 Group(database.Group{
731 QuotaAllowance: 10,
732 }, user).
733 Do()
734
735 // TX mixing tests. **DO NOT** run these in parallel.
736 // The goal here is to mess around with different ordering of
737 // transactions and queries.
738
739 // UpdateBuildDeadline bumps a workspace deadline while doing a quota
740 // commit to the same workspace build.
741 //
742 // Note: This passes if the interrupt is run before 'GetQuota()'
743 // Passing orders:
744 // - BeginTX -> Bump! -> GetQuota -> GetAllowance -> UpdateCost -> EndTx
745 // - BeginTX -> GetQuota -> GetAllowance -> UpdateCost -> Bump! -> EndTx
746 t.Run("UpdateBuildDeadline", func(t *testing.T) {
747 t.Log("Expected to fail. As long as quota & deadline are on the same " +
748 " table and affect the same row, this will likely always fail.")
749
750 // +------------------------------+------------------+
751 // | Begin Tx | |
752 // +------------------------------+------------------+
753 // | GetQuota(user) | |
754 // +------------------------------+------------------+
755 // | | BumpDeadline(w1) |
756 // +------------------------------+------------------+
757 // | GetAllowance(user) | |
758 // +------------------------------+------------------+
759 // | UpdateWorkspaceBuildCost(w1) | |
760 // +------------------------------+------------------+
761 // | CommitTx() | |
762 // +------------------------------+------------------+

Callers

nothing calls this directly

Calls 15

NewDBFunction · 0.92
UserFunction · 0.92
OrganizationFunction · 0.92
ContextFunction · 0.92
WorkspaceBuildFunction · 0.92
NowFunction · 0.92
newCommitterFunction · 0.85
MembersMethod · 0.80
EveryoneAllowanceMethod · 0.80
LogMethod · 0.80
GetQuotaMethod · 0.80
GetAllowanceMethod · 0.80

Tested by

no test coverage detected