Commit 979d65db authored by Lars Lehtonen's avatar Lars Lehtonen Committed by Brad Fitzpatrick

net/smtp: fix dropped test error

Pick up a dropped error in TestSendMailWithAuth() and simplify goroutine
to use an error channel instead of a sync.WaitGroup and an empty struct
doneCh.

Change-Id: Ie70d0f7c4c85835eb682e81d086ce4d9900269e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/205247
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 9a0a8244
...@@ -9,13 +9,13 @@ import ( ...@@ -9,13 +9,13 @@ import (
"bytes" "bytes"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"fmt"
"internal/testenv" "internal/testenv"
"io" "io"
"net" "net"
"net/textproto" "net/textproto"
"runtime" "runtime"
"strings" "strings"
"sync"
"testing" "testing"
"time" "time"
) )
...@@ -642,13 +642,13 @@ func TestSendMailWithAuth(t *testing.T) { ...@@ -642,13 +642,13 @@ func TestSendMailWithAuth(t *testing.T) {
t.Fatalf("Unable to create listener: %v", err) t.Fatalf("Unable to create listener: %v", err)
} }
defer l.Close() defer l.Close()
wg := sync.WaitGroup{}
var done = make(chan struct{}) errCh := make(chan error)
go func() { go func() {
defer wg.Done() defer close(errCh)
conn, err := l.Accept() conn, err := l.Accept()
if err != nil { if err != nil {
t.Errorf("Accept error: %v", err) errCh <- fmt.Errorf("Accept: %v", err)
return return
} }
defer conn.Close() defer conn.Close()
...@@ -659,10 +659,11 @@ func TestSendMailWithAuth(t *testing.T) { ...@@ -659,10 +659,11 @@ func TestSendMailWithAuth(t *testing.T) {
if msg == "EHLO localhost" { if msg == "EHLO localhost" {
tc.PrintfLine("250 mx.google.com at your service") tc.PrintfLine("250 mx.google.com at your service")
} }
// for this test case, there should have no more traffic if err != nil {
<-done errCh <- fmt.Errorf("PrintfLine: %v", err)
return
}
}() }()
wg.Add(1)
err = SendMail(l.Addr().String(), PlainAuth("", "user", "pass", "smtp.google.com"), "test@example.com", []string{"other@example.com"}, []byte(strings.Replace(`From: test@example.com err = SendMail(l.Addr().String(), PlainAuth("", "user", "pass", "smtp.google.com"), "test@example.com", []string{"other@example.com"}, []byte(strings.Replace(`From: test@example.com
To: other@example.com To: other@example.com
...@@ -676,8 +677,10 @@ SendMail is working for me. ...@@ -676,8 +677,10 @@ SendMail is working for me.
if err.Error() != "smtp: server doesn't support AUTH" { if err.Error() != "smtp: server doesn't support AUTH" {
t.Errorf("Expected: smtp: server doesn't support AUTH, got: %s", err) t.Errorf("Expected: smtp: server doesn't support AUTH, got: %s", err)
} }
close(done) err = <-errCh
wg.Wait() if err != nil {
t.Fatalf("server error: %v", err)
}
} }
func TestAuthFailed(t *testing.T) { func TestAuthFailed(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment