Skip to content

Commit

Permalink
Do not call t.Errorf out of the test goroutine.
Browse files Browse the repository at this point in the history
  • Loading branch information
lugu committed Nov 14, 2023
1 parent 7599824 commit 9125c55
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 38 deletions.
5 changes: 2 additions & 3 deletions bus/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

func TestCancelledProxyCall(t *testing.T) {

serviceEndpoint, clientEndpoint := net.Pipe()
defer serviceEndpoint.Close()
defer clientEndpoint.Close()
Expand All @@ -22,14 +21,14 @@ func TestCancelledProxyCall(t *testing.T) {
go func() {
m, ok := <-msgChan
if !ok {
t.Fatalf("connection closed")
panic("closed channel")
}
m.Header.Type = net.Cancelled
m.Header.Size = 0
m.Payload = []byte{}
err := serviceEndpoint.Send(*m)
if err != nil {
t.Errorf("send meesage: %s", err)
panic(err)
}
}()

Expand Down
20 changes: 7 additions & 13 deletions bus/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func TestClientCall(t *testing.T) {

serviceEndpoint, clientEndpoint := net.Pipe()
defer serviceEndpoint.Close()
defer clientEndpoint.Close()
Expand All @@ -25,12 +24,12 @@ func TestClientCall(t *testing.T) {
go func() {
m, ok := <-msgChan
if !ok {
t.Fatalf("connection closed")
panic("Channel closed")
}
m.Header.Type = net.Reply
err := serviceEndpoint.Send(*m)
if err != nil {
t.Errorf("send meesage: %s", err)
panic(err)
}
}()

Expand All @@ -43,7 +42,6 @@ func TestClientCall(t *testing.T) {
}

func TestClientAlreadyCancelled(t *testing.T) {

serviceEndpoint, clientEndpoint := net.Pipe()
defer serviceEndpoint.Close()
defer clientEndpoint.Close()
Expand All @@ -58,7 +56,6 @@ func TestClientAlreadyCancelled(t *testing.T) {
}

func TestClientCancel(t *testing.T) {

serviceEndpoint, clientEndpoint := net.Pipe()
defer serviceEndpoint.Close()
defer clientEndpoint.Close()
Expand All @@ -75,22 +72,22 @@ func TestClientCancel(t *testing.T) {
go func() {
m, ok := <-msgChan
if !ok {
t.Fatalf("connection closed")
panic("connection closed")
}
if m.Header.Type != net.Call {
t.Errorf("not a call")
panic("not a call")
}
msgChan, err = serviceEndpoint.ReceiveAny()
if err != nil {
t.Error(err)
panic(err)
}
close(testSync)
m, ok = <-msgChan
if !ok {
t.Fatalf("connection closed")
panic("connection closed")
}
if m.Header.Type != net.Cancel {
t.Errorf("not a cancel")
panic("not a cancel")
}
m.Header.Type = net.Cancelled
serviceEndpoint.Send(net.NewMessage(m.Header, []byte{}))
Expand Down Expand Up @@ -162,7 +159,6 @@ func TestSelectEndPoint(t *testing.T) {
}

func TestClientDisconnectionError(t *testing.T) {

serviceEndpoint, clientEndpoint := net.Pipe()
defer clientEndpoint.Close()

Expand All @@ -187,7 +183,6 @@ func TestClientDisconnectionError(t *testing.T) {
}

func TestClientState(t *testing.T) {

_, clientEndpoint := net.Pipe()
defer clientEndpoint.Close()

Expand Down Expand Up @@ -216,7 +211,6 @@ func TestClientState(t *testing.T) {
}

func TestClientDisconnectionSuccess(t *testing.T) {

serviceEndpoint, clientEndpoint := net.Pipe()
defer serviceEndpoint.Close()

Expand Down
8 changes: 3 additions & 5 deletions bus/net/endpoint_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net_test

import (
"io/ioutil"
gonet "net"
"os"
"reflect"
Expand All @@ -13,7 +12,7 @@ import (
)

func TestConnectUnix(t *testing.T) {
f, err := ioutil.TempFile("", "go-net-test")
f, err := os.CreateTemp("", "go-net-test")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -96,7 +95,6 @@ func TestReceiveOne(t *testing.T) {
}

func TestPingPong(t *testing.T) {

server, client := net.Pipe()
defer server.Close()
defer client.Close()
Expand All @@ -109,11 +107,11 @@ func TestPingPong(t *testing.T) {
go func() {
m, ok := <-srvChan
if !ok {
t.Fatalf("receive meesage")
panic("receive meesage")
}
err = server.Send(*m)
if err != nil {
t.Errorf("send meesage: %s", err)
panic(err)
}
wait.Done()
}()
Expand Down
6 changes: 2 additions & 4 deletions bus/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

func TestProxyCall(t *testing.T) {

serviceEndpoint, clientEndpoint := net.Pipe()
defer serviceEndpoint.Close()
defer clientEndpoint.Close()
Expand All @@ -26,12 +25,12 @@ func TestProxyCall(t *testing.T) {
go func() {
m, ok := <-msgChan
if !ok {
t.Fatalf("connection closed")
panic("connection closed")
}
m.Header.Type = net.Reply
err := serviceEndpoint.Send(*m)
if err != nil {
t.Errorf("send meesage: %s", err)
panic(err)
}
}()

Expand All @@ -45,7 +44,6 @@ func TestProxyCall(t *testing.T) {
}

func TestProxySubscribe(t *testing.T) {

addr := util.NewUnixAddr()

server, err := directory.NewServer(addr, nil)
Expand Down
20 changes: 7 additions & 13 deletions examples/pong/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ func TestPingPong(t *testing.T) {
service := pong.PingPongObject(pong.PingPongImpl())
_, err = server.NewService("PingPong", service)
if err != nil {
panic(err)
t.Fatalf("%s", err)
}

session, err := sess.NewSession(addr)
if err != nil {
panic(err)
t.Fatalf("%s", err)
}
defer session.Terminate()
client, err := pong.PingPong(session)
if err != nil {
panic(err)
t.Fatalf("%s", err)
}

cancel, pong, err := client.SubscribePong()
if err != nil {
panic(err)
t.Fatalf("%s", err)
}
defer cancel()

response, err := client.Hello("hello")
if err != nil {
panic(err)
t.Fatalf("%s", err)
}
if response != "Hello, World!" {
t.Errorf("wrong reply: %s", response)
Expand All @@ -58,7 +58,7 @@ func TestPingPong(t *testing.T) {
answer := <-pong

if answer != "hello" {
panic(err)
t.Errorf("wrong answer: %s", answer)
}
}

Expand All @@ -74,7 +74,7 @@ func testRemoteAddr(b *testing.B, addr string) {
go func() {
select {
case err := <-serverErr:
b.Fatal(err)
panic(err)
case <-quit:
}
}()
Expand Down Expand Up @@ -137,7 +137,6 @@ func BenchmarkPingPongQUIC(b *testing.B) {
}

func BenchmarkPingPongLocal(b *testing.B) {

addr := util.NewUnixAddr()
server, err := dir.NewServer(addr, nil)
if err != nil {
Expand All @@ -156,9 +155,6 @@ func BenchmarkPingPongLocal(b *testing.B) {
}

session := server.Session()
if err != nil {
panic(err)
}
client, err := pong.PingPong(session)
if err != nil {
panic(err)
Expand Down Expand Up @@ -219,7 +215,6 @@ func proxyHello(P0 string) (string, error) {
}

func BenchmarkSerialization(b *testing.B) {

for i := 0; i < b.N; i++ {
reply, err := proxyHello("hello")
if err != nil {
Expand All @@ -232,7 +227,6 @@ func BenchmarkSerialization(b *testing.B) {
}

func BenchmarkImplementation(b *testing.B) {

for i := 0; i < b.N; i++ {
reply, err := implHello("hello")
if err != nil {
Expand Down

0 comments on commit 9125c55

Please sign in to comment.