@@ -5,15 +5,26 @@ import (
5
5
"fmt"
6
6
"io/ioutil"
7
7
"os"
8
+ "sync"
8
9
"time"
9
10
10
11
"github.com/ory/dockertest/v3"
11
12
"github.com/ory/dockertest/v3/docker"
12
13
"golang.org/x/xerrors"
13
14
)
14
15
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
+
15
23
// Open creates a new PostgreSQL server using a Docker container.
16
24
func Open () (string , func (), error ) {
25
+ createMutex .Lock ()
26
+ defer createMutex .Unlock ()
27
+
17
28
pool , err := dockertest .NewPool ("" )
18
29
if err != nil {
19
30
return "" , nil , xerrors .Errorf ("create pool: %w" , err )
@@ -50,6 +61,7 @@ func Open() (string, func(), error) {
50
61
return "" , nil , xerrors .Errorf ("could not start resource: %w" , err )
51
62
}
52
63
hostAndPort := resource .GetHostPort ("5432/tcp" )
64
+ fmt .Printf ("HOST AND PORT %s\n " , hostAndPort )
53
65
dbURL := fmt .Sprintf ("postgres://postgres:postgres@%s/postgres?sslmode=disable" , hostAndPort )
54
66
55
67
// Docker should hard-kill the container after 120 seconds.
0 commit comments