Skip to content

Commit

Permalink
fix: retry for startup, increase reconfigure timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
YC committed Jul 11, 2024
1 parent 03e6961 commit e931e61
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions services/mail/smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"testing"
"time"

"github.com/emvi/logbuch"
"github.com/muety/wakapi/config"
"github.com/muety/wakapi/models"
"github.com/muety/wakapi/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"net/http"
"testing"
"time"
)

const (
Expand All @@ -46,10 +47,16 @@ func (suite *SmtpTestSuite) BeforeTest(suiteName, testName string) {
}

func TestSmtpTestSuite(t *testing.T) {
if smtp4dev := newSmtp4DevClient(); smtp4dev.Check() != nil {
t.Skip(fmt.Sprintf("WARNING: smtp4Dev not available at %s - skipping smtp tests", smtp4dev.ApiBaseUrl))
return
smtp4dev := newSmtp4DevClient()

for i := 0; i < 5; i++ {
if smtp4dev.Check() == nil {
break
}
t.Logf("smtp4Dev not available at %s, retrying...", smtp4dev.ApiBaseUrl)
time.Sleep(1 * time.Second)
}

suite.Run(t, new(SmtpTestSuite))
}

Expand Down Expand Up @@ -201,21 +208,18 @@ func (c *Smtp4DevClient) CountMessages() (int, error) {
func (c *Smtp4DevClient) SetNoTls() error {
logbuch.Info("[smtp4Dev] disabling tls encryption")
err := c.SetConfigValue("tlsMode", "None")
time.Sleep(1 * time.Second)
return err
}

func (c *Smtp4DevClient) SetForcedTls() error {
logbuch.Info("[smtp4Dev] enabling forced tls encryption")
err := c.SetConfigValue("tlsMode", "ImplicitTls")
time.Sleep(1 * time.Second)
return err
}

func (c *Smtp4DevClient) SetStartTls() error {
logbuch.Info("[smtp4Dev] enabling tls encryption via starttls")
err := c.SetConfigValue("tlsMode", "StartTls")
time.Sleep(1 * time.Second)
return err
}

Expand All @@ -228,7 +232,6 @@ func (c *Smtp4DevClient) CreateTestUsers() error {
"defaultMailbox": "Default",
},
})
time.Sleep(100 * time.Millisecond)
return err
}

Expand Down Expand Up @@ -263,5 +266,6 @@ func (c *Smtp4DevClient) SetConfigValue(key string, val interface{}) error {
return err
}

time.Sleep(2 * time.Second)
return nil
}

0 comments on commit e931e61

Please sign in to comment.