Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb9ac16c

Browse files
authored
test(testutil): improve chan.go error visibility (#18406)
1 parentebc769f commitb9ac16c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

‎testutil/chan.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package testutil
33
import (
44
"context"
55
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
69
)
710

811
// TryReceive will attempt to receive a value from the chan and return it. If
@@ -14,7 +17,7 @@ func TryReceive[A any](ctx context.Context, t testing.TB, c <-chan A) A {
1417
t.Helper()
1518
select {
1619
case<-ctx.Done():
17-
t.Fatal("timeout")
20+
require.Fail(t,"TryReceive: context expired")
1821
varaA
1922
returna
2023
casea:=<-c:
@@ -31,12 +34,12 @@ func RequireReceive[A any](ctx context.Context, t testing.TB, c <-chan A) A {
3134
t.Helper()
3235
select {
3336
case<-ctx.Done():
34-
t.Fatal("timeout")
37+
require.Fail(t,"RequireReceive: context expired")
3538
varaA
3639
returna
3740
casea,ok:=<-c:
3841
if!ok {
39-
t.Fatal("channel closed")
42+
require.Fail(t,"RequireReceive:channel closed")
4043
}
4144
returna
4245
}
@@ -50,7 +53,7 @@ func RequireSend[A any](ctx context.Context, t testing.TB, c chan<- A, a A) {
5053
t.Helper()
5154
select {
5255
case<-ctx.Done():
53-
t.Fatal("timeout")
56+
require.Fail(t,"RequireSend: context expired")
5457
casec<-a:
5558
// OK!
5659
}
@@ -68,7 +71,7 @@ func SoftTryReceive[A any](ctx context.Context, t testing.TB, c <-chan A) (A, bo
6871
t.Helper()
6972
select {
7073
case<-ctx.Done():
71-
t.Error("timeout")
74+
assert.Fail(t,"SoftTryReceive: context expired")
7275
varaA
7376
returna,false
7477
casea:=<-c:
@@ -86,12 +89,12 @@ func AssertReceive[A any](ctx context.Context, t testing.TB, c <-chan A) (A, boo
8689
t.Helper()
8790
select {
8891
case<-ctx.Done():
89-
t.Error("timeout")
92+
assert.Fail(t,"AssertReceive: context expired")
9093
varaA
9194
returna,false
9295
casea,ok:=<-c:
9396
if!ok {
94-
t.Error("channel closed")
97+
assert.Fail(t,"AssertReceive:channel closed")
9598
}
9699
returna,ok
97100
}
@@ -107,7 +110,7 @@ func AssertSend[A any](ctx context.Context, t testing.TB, c chan<- A, a A) bool
107110
t.Helper()
108111
select {
109112
case<-ctx.Done():
110-
t.Error("timeout")
113+
assert.Fail(t,"AssertSend: context expired")
111114
returnfalse
112115
casec<-a:
113116
returntrue

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp