@@ -20,6 +20,7 @@ import (
20
20
"github.com/stretchr/testify/require"
21
21
"go.uber.org/goleak"
22
22
"golang.org/x/exp/slices"
23
+ "golang.org/x/sync/errgroup"
23
24
24
25
"github.com/coder/coder/coderd/database/migrations"
25
26
"github.com/coder/coder/coderd/database/postgres"
@@ -47,6 +48,22 @@ func TestMigrate(t *testing.T) {
47
48
require .NoError (t , err )
48
49
})
49
50
51
+ t .Run ("Parallel" , func (t * testing.T ) {
52
+ t .Parallel ()
53
+
54
+ db := testSQLDB (t )
55
+ eg := errgroup.Group {}
56
+
57
+ eg .Go (func () error {
58
+ return migrations .Up (db )
59
+ })
60
+ eg .Go (func () error {
61
+ return migrations .Up (db )
62
+ })
63
+
64
+ require .NoError (t , eg .Wait ())
65
+ })
66
+
50
67
t .Run ("Twice" , func (t * testing.T ) {
51
68
t .Parallel ()
52
69
@@ -86,6 +103,13 @@ func testSQLDB(t testing.TB) *sql.DB {
86
103
require .NoError (t , err )
87
104
t .Cleanup (func () { _ = db .Close () })
88
105
106
+ // postgres.Open automatically runs migrations, but we want to actually test
107
+ // migration behavior in this package.
108
+ _ , err = db .Exec (`DROP SCHEMA public CASCADE` )
109
+ require .NoError (t , err )
110
+ _ , err = db .Exec (`CREATE SCHEMA public` )
111
+ require .NoError (t , err )
112
+
89
113
return db
90
114
}
91
115
0 commit comments