Skip to content

Commit 6ce8bfe

Browse files
committed
tests to assert errors, rather then skip the test
1 parent a99882a commit 6ce8bfe

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

enterprise/coderd/workspacequota_test.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,9 @@ func TestWorkspaceSerialization(t *testing.T) {
349349
// - BeginTX -> Bump! -> GetQuota -> GetAllowance -> UpdateCost -> EndTx
350350
// - BeginTX -> GetQuota -> GetAllowance -> UpdateCost -> Bump! -> EndTx
351351
t.Run("UpdateBuildDeadline", func(t *testing.T) {
352-
t.Skip("Expected to fail. As long as quota & deadline are on the same " +
352+
t.Log("Expected to fail. As long as quota & deadline are on the same " +
353353
" table and affect the same row, this will likely always fail.")
354+
354355
// +------------------------------+------------------+
355356
// | Begin Tx | |
356357
// +------------------------------+------------------+
@@ -393,12 +394,17 @@ func TestWorkspaceSerialization(t *testing.T) {
393394
// Run order
394395

395396
quota := newCommitter(t, db, myWorkspace.Workspace, myWorkspace.Build)
396-
quota.GetQuota(ctx, t) // Step 1
397-
bumpDeadline() // Interrupt
398-
quota.GetAllowance(ctx, t) // Step 2
399-
quota.UpdateWorkspaceBuildCostByID(ctx, t, 10) // Step 3
397+
quota.GetQuota(ctx, t) // Step 1
398+
bumpDeadline() // Interrupt
399+
quota.GetAllowance(ctx, t) // Step 2
400+
401+
err := quota.DBTx.UpdateWorkspaceBuildCostByID(ctx, database.UpdateWorkspaceBuildCostByIDParams{
402+
ID: myWorkspace.Build.ID,
403+
DailyCost: 10,
404+
}) // Step 3
405+
require.ErrorContains(t, err, "could not serialize access due to concurrent update")
400406
// End commit
401-
require.NoError(t, quota.Done())
407+
require.ErrorContains(t, quota.Done(), "failed transaction")
402408
})
403409

404410
// UpdateOtherBuildDeadline bumps a user's other workspace deadline
@@ -465,7 +471,7 @@ func TestWorkspaceSerialization(t *testing.T) {
465471
})
466472

467473
t.Run("ActivityBump", func(t *testing.T) {
468-
t.Skip("Expected to fail. As long as quota & deadline are on the same " +
474+
t.Log("Expected to fail. As long as quota & deadline are on the same " +
469475
" table and affect the same row, this will likely always fail.")
470476
// +---------------------+----------------------------------+
471477
// | W1 Quota Tx | |
@@ -510,10 +516,14 @@ func TestWorkspaceSerialization(t *testing.T) {
510516

511517
assert.NoError(t, err)
512518

513-
one.UpdateWorkspaceBuildCostByID(ctx, t, 10)
519+
err = one.DBTx.UpdateWorkspaceBuildCostByID(ctx, database.UpdateWorkspaceBuildCostByIDParams{
520+
ID: myWorkspace.Build.ID,
521+
DailyCost: 10,
522+
})
523+
require.ErrorContains(t, err, "could not serialize access due to concurrent update")
514524

515525
// End commit
516-
assert.NoError(t, one.Done())
526+
assert.ErrorContains(t, one.Done(), "failed transaction")
517527
})
518528

519529
t.Run("BumpLastUsedAt", func(t *testing.T) {
@@ -724,7 +734,7 @@ func TestWorkspaceSerialization(t *testing.T) {
724734
// QuotaCommit 2 workspaces in the same org.
725735
// Workspaces do not share templates
726736
t.Run("DoubleQuotaUserWorkspaces", func(t *testing.T) {
727-
t.Skip("Setting a new build cost to a workspace in a org affects other " +
737+
t.Log("Setting a new build cost to a workspace in a org affects other " +
728738
"workspaces in the same org. This is expected to fail.")
729739
// +---------------------+---------------------+
730740
// | W1 Quota Tx | W2 Quota Tx |
@@ -779,7 +789,7 @@ func TestWorkspaceSerialization(t *testing.T) {
779789

780790
// End commit
781791
assert.NoError(t, one.Done())
782-
assert.NoError(t, two.Done())
792+
assert.ErrorContains(t, two.Done(), "could not serialize access due to read/write dependencies among transactions")
783793
})
784794
}
785795

0 commit comments

Comments
 (0)