Skip to content

Commit aa64d28

Browse files
committed
ci: Lock PostgreSQL database creation
There have been race conditions when multiple instances are created at once. This is an attempt to fix!
1 parent 5367d93 commit aa64d28

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

database/postgres/postgres.go

+11
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,26 @@ import (
55
"fmt"
66
"io/ioutil"
77
"os"
8+
"sync"
89
"time"
910

1011
"github.com/ory/dockertest/v3"
1112
"github.com/ory/dockertest/v3/docker"
1213
"golang.org/x/xerrors"
1314
)
1415

16+
// Locks the creation of a PostgreSQL instance to one-at-a-time.
17+
// We experienced race conditions when creating multiple instances
18+
// at a time. Somehow they were sharing data...
19+
//
20+
// This may be an upstream issue with "dockertest".
21+
var createMutex sync.Mutex
22+
1523
// Open creates a new PostgreSQL server using a Docker container.
1624
func Open() (string, func(), error) {
25+
createMutex.Lock()
26+
defer createMutex.Unlock()
27+
1728
pool, err := dockertest.NewPool("")
1829
if err != nil {
1930
return "", nil, xerrors.Errorf("create pool: %w", err)

0 commit comments

Comments
 (0)