mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
chore: increase parallelism of TestWorkspaceQuota (#6710)
This does a lot of build operations, so having multiple provisioner daemons is great. We were actually approaching the ceiling here for test duration!
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/lib/pq"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/coderd/database"
|
||||
@ -15,6 +16,36 @@ import (
|
||||
"github.com/coder/coder/coderd/database/postgres"
|
||||
)
|
||||
|
||||
func TestSerializedRetry(t *testing.T) {
|
||||
t.Parallel()
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
sqlDB := testSQLDB(t)
|
||||
db := database.New(sqlDB)
|
||||
|
||||
called := 0
|
||||
txOpts := &sql.TxOptions{Isolation: sql.LevelSerializable}
|
||||
err := db.InTx(func(tx database.Store) error {
|
||||
// Test nested error
|
||||
return tx.InTx(func(tx database.Store) error {
|
||||
// The easiest way to mock a serialization failure is to
|
||||
// return a serialization failure error.
|
||||
called++
|
||||
return &pq.Error{
|
||||
Code: "40001",
|
||||
Message: "serialization_failure",
|
||||
}
|
||||
}, txOpts)
|
||||
}, txOpts)
|
||||
require.Error(t, err, "should fail")
|
||||
// The double "execute transaction: execute transaction" is from the nested transactions.
|
||||
// Just want to make sure we don't try 9 times.
|
||||
require.Equal(t, err.Error(), "transaction failed after 3 attempts: execute transaction: execute transaction: pq: serialization_failure", "error message")
|
||||
require.Equal(t, called, 3, "should retry 3 times")
|
||||
}
|
||||
|
||||
func TestNestedInTx(t *testing.T) {
|
||||
t.Parallel()
|
||||
if testing.Short() {
|
||||
|
Reference in New Issue
Block a user