Skip to content

Commit

Permalink
fix: add mutex to test SMTP server setup/teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr committed Mar 9, 2023
1 parent b87b723 commit 20c2359
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion x/mailhog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"os"
"sync"
"time"

"github.com/cenkalti/backoff"
Expand All @@ -15,12 +16,18 @@ import (
"github.com/ory/dockertest/v3"
)

var resources []*dockertest.Resource
var (
resourceMux sync.Mutex
resources []*dockertest.Resource
)

func CleanUpTestSMTP() {
resourceMux.Lock()
defer resourceMux.Unlock()
for _, resource := range resources {
resource.Close()
}
resources = nil
}

func RunTestSMTP() (smtp, api string, err error) {
Expand Down Expand Up @@ -53,7 +60,9 @@ func RunTestSMTP() (smtp, api string, err error) {
if err != nil {
return "", "", err
}
resourceMux.Lock()
resources = append(resources, resource)
resourceMux.Unlock()

smtp = fmt.Sprintf("smtp://test:test@127.0.0.1:%s/?disable_starttls=true", resource.GetPort("1025/tcp"))
api = fmt.Sprintf("http://127.0.0.1:%s", resource.GetPort("8025/tcp"))
Expand Down

0 comments on commit 20c2359

Please sign in to comment.