@@ -356,6 +356,8 @@ func TestWorkspaceSerialization(t *testing.T) {
356
356
// - BeginTX -> Bump! -> GetQuota -> GetAllowance -> UpdateCost -> EndTx
357
357
// - BeginTX -> GetQuota -> GetAllowance -> UpdateCost -> Bump! -> EndTx
358
358
t .Run ("UpdateBuildDeadline" , func (t * testing.T ) {
359
+ t .Skip ("Expected to fail. As long as quota & deadline are on the same " +
360
+ " table and affect the same row, this will likely always fail." )
359
361
// +------------------------------+------------------+
360
362
// | Begin Tx | |
361
363
// +------------------------------+------------------+
@@ -470,6 +472,8 @@ func TestWorkspaceSerialization(t *testing.T) {
470
472
})
471
473
472
474
t .Run ("ActivityBump" , func (t * testing.T ) {
475
+ t .Skip ("Expected to fail. As long as quota & deadline are on the same " +
476
+ " table and affect the same row, this will likely always fail." )
473
477
// +---------------------+----------------------------------+
474
478
// | W1 Quota Tx | |
475
479
// +---------------------+----------------------------------+
@@ -528,7 +532,7 @@ func TestWorkspaceSerialization(t *testing.T) {
528
532
// +---------------------+----------------------------------+
529
533
// | GetAllowance(w1) | |
530
534
// +---------------------+----------------------------------+
531
- // | | UpdateWorkspaceBuildDeadline (w1) |
535
+ // | | UpdateWorkspaceLastUsedAt (w1) |
532
536
// +---------------------+----------------------------------+
533
537
// | UpdateBuildCost(w1) | |
534
538
// +---------------------+----------------------------------+
@@ -549,11 +553,9 @@ func TestWorkspaceSerialization(t *testing.T) {
549
553
one .GetQuota (ctx , t )
550
554
one .GetAllowance (ctx , t )
551
555
552
- err := db .UpdateWorkspaceBuildDeadlineByID (ctx , database.UpdateWorkspaceBuildDeadlineByIDParams {
553
- Deadline : dbtime .Now (),
554
- MaxDeadline : dbtime .Now (),
555
- UpdatedAt : dbtime .Now (),
556
- ID : myWorkspace .Build .ID ,
556
+ err := db .UpdateWorkspaceLastUsedAt (ctx , database.UpdateWorkspaceLastUsedAtParams {
557
+ ID : myWorkspace .Workspace .ID ,
558
+ LastUsedAt : dbtime .Now (),
557
559
})
558
560
assert .NoError (t , err )
559
561
@@ -610,7 +612,7 @@ func TestWorkspaceSerialization(t *testing.T) {
610
612
611
613
// QuotaCommit 2 workspaces in different orgs.
612
614
// Workspaces do not share templates, owners, or orgs
613
- t .Run ("DoubleQuotaWorkspaces " , func (t * testing.T ) {
615
+ t .Run ("DoubleQuotaUnrelatedWorkspaces " , func (t * testing.T ) {
614
616
// +---------------------+---------------------+
615
617
// | W1 Quota Tx | W2 Quota Tx |
616
618
// +---------------------+---------------------+
@@ -634,7 +636,6 @@ func TestWorkspaceSerialization(t *testing.T) {
634
636
// +---------------------+---------------------+
635
637
// | | CommitTx() |
636
638
// +---------------------+---------------------+
637
- // pq: could not serialize access due to read/write dependencies among transactions
638
639
ctx := testutil .Context (t , testutil .WaitLong )
639
640
ctx = dbauthz .AsSystemRestricted (ctx )
640
641
@@ -667,9 +668,124 @@ func TestWorkspaceSerialization(t *testing.T) {
667
668
assert .NoError (t , two .Done ())
668
669
})
669
670
670
- // Autobuild, then quota, then autobuild read agin in the same tx
671
- // https://www.richardstrnad.ch/posts/go-sql-how-to-get-detailed-error/
672
- // https://blog.danslimmon.com/2024/01/10/why-transaction-order-matters-even-if-youre-only-reading/
671
+ // QuotaCommit 2 workspaces in different orgs.
672
+ // Workspaces do not share templates or orgs
673
+ t .Run ("DoubleQuotaUserWorkspacesDiffOrgs" , func (t * testing.T ) {
674
+ // +---------------------+---------------------+
675
+ // | W1 Quota Tx | W2 Quota Tx |
676
+ // +---------------------+---------------------+
677
+ // | Begin Tx | |
678
+ // +---------------------+---------------------+
679
+ // | | Begin Tx |
680
+ // +---------------------+---------------------+
681
+ // | GetQuota(w1) | |
682
+ // +---------------------+---------------------+
683
+ // | GetAllowance(w1) | |
684
+ // +---------------------+---------------------+
685
+ // | UpdateBuildCost(w1) | |
686
+ // +---------------------+---------------------+
687
+ // | | UpdateBuildCost(w2) |
688
+ // +---------------------+---------------------+
689
+ // | | GetQuota(w2) |
690
+ // +---------------------+---------------------+
691
+ // | | GetAllowance(w2) |
692
+ // +---------------------+---------------------+
693
+ // | CommitTx() | |
694
+ // +---------------------+---------------------+
695
+ // | | CommitTx() |
696
+ // +---------------------+---------------------+
697
+ ctx := testutil .Context (t , testutil .WaitLong )
698
+ ctx = dbauthz .AsSystemRestricted (ctx )
699
+
700
+ myWorkspace := dbfake .WorkspaceBuild (t , db , database.WorkspaceTable {
701
+ OrganizationID : org .Org .ID ,
702
+ OwnerID : user .ID ,
703
+ }).Do ()
704
+
705
+ myOtherWorkspace := dbfake .WorkspaceBuild (t , db , database.WorkspaceTable {
706
+ OrganizationID : otherOrg .Org .ID , // Different org!
707
+ OwnerID : user .ID ,
708
+ }).Do ()
709
+
710
+ one := newCommitter (t , db , myWorkspace .Workspace , myWorkspace .Build )
711
+ two := newCommitter (t , db , myOtherWorkspace .Workspace , myOtherWorkspace .Build )
712
+
713
+ var _ , _ = one , two
714
+ // Run order
715
+ one .GetQuota (ctx , t )
716
+ one .GetAllowance (ctx , t )
717
+
718
+ one .UpdateWorkspaceBuildCostByID (ctx , t , 10 )
719
+
720
+ two .GetQuota (ctx , t )
721
+ two .GetAllowance (ctx , t )
722
+ two .UpdateWorkspaceBuildCostByID (ctx , t , 10 )
723
+
724
+ // End commit
725
+ assert .NoError (t , one .Done ())
726
+ assert .NoError (t , two .Done ())
727
+ })
728
+
729
+ // QuotaCommit 2 workspaces in the same org.
730
+ // Workspaces do not share templates
731
+ t .Run ("DoubleQuotaUserWorkspaces" , func (t * testing.T ) {
732
+ t .Skip ("Setting a new build cost to a workspace in a org affects other " +
733
+ "workspaces in the same org. This is expected to fail." )
734
+ // +---------------------+---------------------+
735
+ // | W1 Quota Tx | W2 Quota Tx |
736
+ // +---------------------+---------------------+
737
+ // | Begin Tx | |
738
+ // +---------------------+---------------------+
739
+ // | | Begin Tx |
740
+ // +---------------------+---------------------+
741
+ // | GetQuota(w1) | |
742
+ // +---------------------+---------------------+
743
+ // | GetAllowance(w1) | |
744
+ // +---------------------+---------------------+
745
+ // | UpdateBuildCost(w1) | |
746
+ // +---------------------+---------------------+
747
+ // | | UpdateBuildCost(w2) |
748
+ // +---------------------+---------------------+
749
+ // | | GetQuota(w2) |
750
+ // +---------------------+---------------------+
751
+ // | | GetAllowance(w2) |
752
+ // +---------------------+---------------------+
753
+ // | CommitTx() | |
754
+ // +---------------------+---------------------+
755
+ // | | CommitTx() |
756
+ // +---------------------+---------------------+
757
+ // pq: could not serialize access due to read/write dependencies among transactions
758
+ ctx := testutil .Context (t , testutil .WaitLong )
759
+ ctx = dbauthz .AsSystemRestricted (ctx )
760
+
761
+ myWorkspace := dbfake .WorkspaceBuild (t , db , database.WorkspaceTable {
762
+ OrganizationID : org .Org .ID ,
763
+ OwnerID : user .ID ,
764
+ }).Do ()
765
+
766
+ myOtherWorkspace := dbfake .WorkspaceBuild (t , db , database.WorkspaceTable {
767
+ OrganizationID : org .Org .ID ,
768
+ OwnerID : user .ID ,
769
+ }).Do ()
770
+
771
+ one := newCommitter (t , db , myWorkspace .Workspace , myWorkspace .Build )
772
+ two := newCommitter (t , db , myOtherWorkspace .Workspace , myOtherWorkspace .Build )
773
+
774
+ var _ , _ = one , two
775
+ // Run order
776
+ one .GetQuota (ctx , t )
777
+ one .GetAllowance (ctx , t )
778
+
779
+ one .UpdateWorkspaceBuildCostByID (ctx , t , 10 )
780
+
781
+ two .GetQuota (ctx , t )
782
+ two .GetAllowance (ctx , t )
783
+ two .UpdateWorkspaceBuildCostByID (ctx , t , 10 )
784
+
785
+ // End commit
786
+ assert .NoError (t , one .Done ())
787
+ assert .NoError (t , two .Done ())
788
+ })
673
789
}
674
790
675
791
func deprecatedQuotaEndpoint (ctx context.Context , client * codersdk.Client , userID string ) (codersdk.WorkspaceQuota , error ) {
0 commit comments