@@ -417,13 +417,12 @@ func TestWorkspaceSerialization(t *testing.T) {
417
417
// +---------------------+----------------------------------+
418
418
// | GetAllowance(w1) | |
419
419
// +---------------------+----------------------------------+
420
- // | | ActivityBump(w1) |
420
+ // | | ActivityBump(w1 |
421
421
// +---------------------+----------------------------------+
422
422
// | UpdateBuildCost(w1) | |
423
423
// +---------------------+----------------------------------+
424
424
// | CommitTx() | |
425
425
// +---------------------+----------------------------------+
426
- // pq: could not serialize access due to concurrent update
427
426
ctx := testutil .Context (t , testutil .WaitShort )
428
427
ctx = dbauthz .AsSystemRestricted (ctx )
429
428
@@ -451,6 +450,51 @@ func TestWorkspaceSerialization(t *testing.T) {
451
450
assert .NoError (t , one .Done ())
452
451
})
453
452
453
+ t .Run ("BumpLastUsedAt" , func (t * testing.T ) {
454
+ // +---------------------+----------------------------------+
455
+ // | W1 Quota Tx | |
456
+ // +---------------------+----------------------------------+
457
+ // | Begin Tx | |
458
+ // +---------------------+----------------------------------+
459
+ // | GetQuota(w1) | |
460
+ // +---------------------+----------------------------------+
461
+ // | GetAllowance(w1) | |
462
+ // +---------------------+----------------------------------+
463
+ // | | UpdateWorkspaceBuildDeadline(w1) |
464
+ // +---------------------+----------------------------------+
465
+ // | UpdateBuildCost(w1) | |
466
+ // +---------------------+----------------------------------+
467
+ // | CommitTx() | |
468
+ // +---------------------+----------------------------------+
469
+ // pq: could not serialize access due to concurrent update
470
+ ctx := testutil .Context (t , testutil .WaitShort )
471
+ ctx = dbauthz .AsSystemRestricted (ctx )
472
+
473
+ myWorkspace := dbfake .WorkspaceBuild (t , db , database.WorkspaceTable {
474
+ OrganizationID : org .Org .ID ,
475
+ OwnerID : user .ID ,
476
+ }).Do ()
477
+
478
+ one := newCommitter (t , db , myWorkspace .Workspace , myWorkspace .Build )
479
+
480
+ // Run order
481
+ one .GetQuota (ctx , t )
482
+ one .GetAllowance (ctx , t )
483
+
484
+ err := db .UpdateWorkspaceBuildDeadlineByID (ctx , database.UpdateWorkspaceBuildDeadlineByIDParams {
485
+ Deadline : dbtime .Now (),
486
+ MaxDeadline : dbtime .Now (),
487
+ UpdatedAt : dbtime .Now (),
488
+ ID : myWorkspace .Build .ID ,
489
+ })
490
+ assert .NoError (t , err )
491
+
492
+ one .UpdateWorkspaceBuildCostByID (ctx , t , 10 )
493
+
494
+ // End commit
495
+ assert .NoError (t , one .Done ())
496
+ })
497
+
454
498
// Workspace
455
499
// User: 1
456
500
// Tpl: 1
@@ -935,44 +979,6 @@ func TestWorkspaceSerialization(t *testing.T) {
935
979
// assert.NoError(t, one.Done())
936
980
//})
937
981
//
938
- //// TODO: Try to fail a non-repeatable read only transaction
939
- //t.Run("ReadStale", func(t *testing.T) {
940
- // ctx := testutil.Context(t, testutil.WaitLong)
941
- // ctx = dbauthz.AsSystemRestricted(ctx)
942
- //
943
- // three := newCommitter(t, db, workspace, workspaceTwoResp.Build)
944
- // two := newCommitter(t, db, workspaceTwo, workspaceResp.Build)
945
- // one := newCommitter(t, db, workspace, workspaceResp.Build)
946
- // three.UpdateWorkspaceBuildCostByID(ctx, t, 10)
947
- //
948
- // // Run order
949
- //
950
- // fmt.Println("1", one.GetQuota(ctx, t))
951
- // one.GetAllowance(ctx, t)
952
- //
953
- // one.UpdateWorkspaceBuildCostByID(ctx, t, 10)
954
- //
955
- // fmt.Println("1a", one.GetQuota(ctx, t))
956
- //
957
- // fmt.Println("2a", two.GetQuota(ctx, t))
958
- // two.GetAllowance(ctx, t)
959
- //
960
- // // End commit
961
- // assert.NoError(t, one.Done())
962
- //
963
- // fmt.Println("2a", two.GetQuota(ctx, t))
964
- // two.GetAllowance(ctx, t)
965
- //
966
- // assert.NoError(t, two.Done())
967
- // assert.NoError(t, three.Done())
968
- //
969
- // //allow, err = db.GetQuotaConsumedForUser(ctx, database.GetQuotaConsumedForUserParams{
970
- // // OwnerID: user.ID,
971
- // // OrganizationID: org.ID,
972
- // //})
973
- // //require.NoError(t, err)
974
- // //fmt.Println(allow)
975
- //})
976
982
977
983
// Autobuild, then quota, then autobuild read agin in the same tx
978
984
// https://www.richardstrnad.ch/posts/go-sql-how-to-get-detailed-error/
0 commit comments