Don't call Fatal() on background thread in test

It doesn't fail the test
This commit is contained in:
Bryan Boreham
2021-04-04 12:07:10 +01:00
parent 2ddcd9c067
commit 2cf48f2bdd
4 changed files with 22 additions and 21 deletions

View File

@@ -2,14 +2,14 @@ package multitenant
import (
"bytes"
"context"
"fmt"
"io"
"log"
"math/rand"
"sync"
"testing"
"context"
"golang.org/x/sync/errgroup"
"github.com/weaveworks/scope/app"
"github.com/weaveworks/scope/common/xfer"
@@ -38,37 +38,34 @@ type pipeconn struct {
func (p *pipeconn) test(t *testing.T) {
msg := []byte("hello " + p.id)
wait := sync.WaitGroup{}
wait.Add(2)
go func() {
defer wait.Done()
wait := errgroup.Group{}
wait.Go(func() error {
// write something to the probe end
_, err := p.probeIO.Write(msg)
if err != nil {
t.Fatal(err)
}
}()
go func() {
defer wait.Done()
return err
})
wait.Go(func() error {
// read it back off the other end
buf := make([]byte, len(msg))
n, err := p.uiIO.Read(buf)
if n != len(buf) {
t.Fatalf("only read %d", n)
}
if err != nil {
t.Fatal(err)
return err
}
if n != len(buf) {
return fmt.Errorf("only read %d", n)
}
if !bytes.Equal(buf, msg) {
t.Fatalf("Got: %v, Expected: %v", buf, msg)
return fmt.Errorf("Got: %v, Expected: %v", buf, msg)
}
}()
return nil
})
wait.Wait()
err := wait.Wait()
if err != nil {
t.Fatal(err)
}
}
type pipeTest struct {

1
go.mod
View File

@@ -82,6 +82,7 @@ require (
github.com/weaveworks/weave v2.3.1-0.20180427133448-4da998ab4507+incompatible
github.com/willdonnelly/passwd v0.0.0-20141013001024-7935dab3074c
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82
golang.org/x/text v0.3.1-0.20171227012246-e19ae1496984 // indirect
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2

1
go.sum
View File

@@ -364,6 +364,7 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180824143301-4910a1d54f87/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

2
vendor/modules.txt vendored
View File

@@ -379,6 +379,8 @@ golang.org/x/net/trace
# golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
golang.org/x/oauth2
golang.org/x/oauth2/internal
# golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/sync/errgroup
# golang.org/x/sys v0.0.0-20200122134326-e047566fdf82
golang.org/x/sys/unix
golang.org/x/sys/windows