go-pkgz / email

Email library to send simple messages
https://go-pkgz.umputun.dev/email/
MIT License
21 stars 6 forks source link

Sender timeOut doesn't work for TLS connections #17

Closed gurza closed 1 year ago

gurza commented 1 year ago

Let's try to use passive loopback ip addresses in TestEmail_SendFailedMakeClient test for TLS Sender. 127.0.0.2 instead of 127.0.0.1 This is a general way to receive timeout network error.

func TestEmail_SendFailedMakeClient(t *testing.T) {
    // ...
    {
        s := NewSender("127.0.0.2", Port(225), TLS(true), TimeOut(time.Millisecond*200))
        err := s.Send("some text", Params{
            From:    "from@example.com",
            To:      []string{"to@example.com"},
            Subject: "subj",
        })
        require.Error(t, err)
    }
}

Run this test:

/usr/local/bin/go test -timeout 30s -run ^TestEmail_SendFailedMakeClient$ github.com/go-pkgz/email

The test will fail with panic message panic: test timed out after 30s. Whereas we expect to receive timeout network error cuz Sender timeout was set to 200ms TimeOut(time.Millisecond*200).

gurza commented 1 year ago

In test it is better to use an 198.18.0.254 (IPv6 2001:2::254) address which is expected to hang until the timeout elapses on both MacOS and Linux.