Skip to content

Commit b69dd0f

Browse files
committed
revert some changes
1 parent 426eeb6 commit b69dd0f

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

coderd/database/dbtestutil/tx.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ import (
1010
type DBTx struct {
1111
database.Store
1212
mu sync.Mutex
13-
err error
14-
errC chan error
13+
done chan error
1514
finalErr chan error
1615
}
1716

1817
// StartTx starts a transaction and returns a DBTx object. This allows running
1918
// 2 transactions concurrently in a test more easily.
19+
// Example:
20+
//
21+
// a := StartTx(t, db, opts)
22+
// b := StartTx(t, db, opts)
23+
//
24+
// a.GetUsers(...)
25+
// b.GetUsers(...)
26+
//
27+
// require.NoError(t, a.Done()
2028
func StartTx(t *testing.T, db database.Store, opts *database.TxOptions) *DBTx {
2129
errC := make(chan error)
2230
finalErr := make(chan error)
@@ -34,31 +42,31 @@ func StartTx(t *testing.T, db database.Store, opts *database.TxOptions) *DBTx {
3442
})
3543
count++
3644
if count > 1 {
45+
// If you recursively call InTx, then don't use this.
3746
t.Logf("InTx called more than once: %d", count)
47+
t.Fatal("InTx called more than once, this is not allowed with the StartTx helper")
3848
}
39-
return <-errC
49+
50+
select {
51+
case _, _ = <-errC:
52+
}
53+
// Just return nil. The caller should be checking their own errors.
54+
return nil
4055
}, opts)
4156
finalErr <- err
4257
}()
4358

4459
txStore := <-txC
4560
close(txC)
4661

47-
return &DBTx{Store: txStore, errC: errC, finalErr: finalErr}
48-
}
49-
50-
func (tx *DBTx) SetError(err error) {
51-
tx.mu.Lock()
52-
defer tx.mu.Unlock()
53-
tx.err = err
62+
return &DBTx{Store: txStore, done: errC, finalErr: finalErr}
5463
}
5564

5665
// Done can only be called once. If you call it twice, it will panic.
5766
func (tx *DBTx) Done() error {
5867
tx.mu.Lock()
5968
defer tx.mu.Unlock()
6069

61-
tx.errC <- tx.err
62-
close(tx.errC)
70+
close(tx.done)
6371
return <-tx.finalErr
6472
}

enterprise/coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
701701

702702
if initial, changed, enabled := featureChanged(codersdk.FeatureTemplateRBAC); shouldUpdate(initial, changed, enabled) {
703703
if enabled {
704-
committer := Committer{
704+
committer := committer{
705705
Log: api.Logger.Named("quota_committer"),
706706
Database: api.Database,
707707
}

enterprise/coderd/workspacequota.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import (
1818
"github.com/coder/coder/v2/provisionerd/proto"
1919
)
2020

21-
type Committer struct {
21+
type committer struct {
2222
Log slog.Logger
2323
Database database.Store
2424
}
2525

26-
func (c *Committer) CommitQuota(
26+
func (c *committer) CommitQuota(
2727
ctx context.Context, request *proto.CommitQuotaRequest,
2828
) (*proto.CommitQuotaResponse, error) {
2929
jobID, err := uuid.Parse(request.JobId)

0 commit comments

Comments
 (0)