Wrap StartDbInDocker in a mutex. (#275)

* Wrap StartDbInDocker in a mutex.

* Adding TODO to debug further.

* Clarifying the TODO to point out a race condition.
This commit is contained in:
Todd Knight authored and GitHub committed 2020-08-17 10:18:46 -07:00
1 parent 1deea8aa3a
commit 01059e6ca8
1 file changed
+8
+8
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"os"
"strings"
"sync"
"github.com/golang-migrate/migrate/v4"
"github.com/hashicorp/boundary/internal/db/migrations"
@@ -80,8 +81,15 @@ func InitDbInDocker(dialect string) (cleanup func() error, retURL, container str
return c, url, container, nil
}
var (
mx = sync.Mutex{}
)
// StartDbInDocker
func StartDbInDocker(dialect string) (cleanup func() error, retURL, container string, err error) {
// TODO: Debug what part of this method is actually causing race condition issues with our test and fix.
mx.Lock()
defer mx.Unlock()
pool, err := dockertest.NewPool("")
if err != nil {
return func() error { return nil }, "", "", fmt.Errorf("could not connect to docker: %w", err)