From 979d65dbc7687ca4c0bc76576d37affae7b7c041 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Mon, 4 Nov 2019 18:13:06 -0800 Subject: [PATCH] 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 Reviewed-by: Brad Fitzpatrick --- src/net/smtp/smtp_test.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/net/smtp/smtp_test.go b/src/net/smtp/smtp_test.go index 8195f91419..2ad7dd0978 100644 --- a/src/net/smtp/smtp_test.go +++ b/src/net/smtp/smtp_test.go @@ -9,13 +9,13 @@ import ( "bytes" "crypto/tls" "crypto/x509" + "fmt" "internal/testenv" "io" "net" "net/textproto" "runtime" "strings" - "sync" "testing" "time" ) @@ -642,13 +642,13 @@ func TestSendMailWithAuth(t *testing.T) { t.Fatalf("Unable to create listener: %v", err) } defer l.Close() - wg := sync.WaitGroup{} - var done = make(chan struct{}) + + errCh := make(chan error) go func() { - defer wg.Done() + defer close(errCh) conn, err := l.Accept() if err != nil { - t.Errorf("Accept error: %v", err) + errCh <- fmt.Errorf("Accept: %v", err) return } defer conn.Close() @@ -659,10 +659,11 @@ func TestSendMailWithAuth(t *testing.T) { if msg == "EHLO localhost" { tc.PrintfLine("250 mx.google.com at your service") } - // for this test case, there should have no more traffic - <-done + if err != nil { + 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 To: other@example.com @@ -676,8 +677,10 @@ SendMail is working for me. if err.Error() != "smtp: server doesn't support AUTH" { t.Errorf("Expected: smtp: server doesn't support AUTH, got: %s", err) } - close(done) - wg.Wait() + err = <-errCh + if err != nil { + t.Fatalf("server error: %v", err) + } } func TestAuthFailed(t *testing.T) { -- 2.48.1