]> Cypherpunks repositories - gostls13.git/commitdiff
net/smtp: fix dropped test error
authorLars Lehtonen <lars.lehtonen@gmail.com>
Tue, 5 Nov 2019 02:13:06 +0000 (18:13 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 5 Nov 2019 03:50:54 +0000 (03:50 +0000)
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: Brad Fitzpatrick <bradfitz@golang.org>
src/net/smtp/smtp_test.go

index 8195f91419e33f8b46a0776aeb1b2eae5d8ce101..2ad7dd0978fb89a9f4c208fac9527e14c9d0e83d 100644 (file)
@@ -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) {