Skip to content

Commit 6c112da

Browse files
authored
test: improve gRPC unit tests stability (#1800)
1 parent fefa17d commit 6c112da

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

.codecov.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ github_checks:
33

44
ignore:
55
- "tool/**/*.go"
6+
7+
coverage:
8+
status:
9+
project:
10+
default:
11+
# pass if coverage drops by no more than 0.05%
12+
# this is possibly caused by unstable coverage.
13+
threshold: 0.05%

pkg/remote/trans/nphttp2/grpc/transport_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,27 @@ func TestMaxStreams(t *testing.T) {
10331033
t.Fatalf("%s", "Test failed: didn't expect new stream to be created just yet.")
10341034
default:
10351035
}
1036+
blocked := make(chan struct{})
1037+
go func() {
1038+
for {
1039+
ok, _ := ct.controlBuf.execute(func(it interface{}) bool {
1040+
// The last stream that fails with context deadline exceeded makes waitingStreams +1.
1041+
// To make sure that the new stream is blocking because of streamQuota, we need to make sure that
1042+
// streamQuota is 0 and waitingStreams is greater than 1
1043+
if ct.streamQuota == 0 && ct.waitingStreams > 1 {
1044+
return true
1045+
}
1046+
return false
1047+
}, nil)
1048+
if ok {
1049+
close(blocked)
1050+
return
1051+
}
1052+
time.Sleep(100 * time.Millisecond)
1053+
}
1054+
}()
1055+
// wait for creating the new stream is blocking actually
1056+
<-blocked
10361057
// Close the first stream created so that the new stream can finally be created.
10371058
ct.CloseStream(s, nil)
10381059
<-done

0 commit comments

Comments
 (0)