snapshot of https://github.com/grpc/grpc-go.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (push) Failing after 1s
Testing / vet-proto (push) Failing after 1s
Testing / tests (arm, latest) (push) Waiting to run
Testing / extras (latest) (push) Failing after 1s
Testing / static checks (latest-1) (push) Failing after 1s
Testing / tests (-race, latest) (push) Failing after 1s
Testing / tests (i386, latest) (push) Failing after 1s
Testing / tests (latest) (push) Failing after 1s
Testing / tests (latest-1) (push) Failing after 1s
Lock Threads / lock (push) Failing after 1s
govulncheck / govulncheck (.) (push) Failing after 1s
govulncheck / govulncheck (./cmd/protoc-gen-go-grpc) (push) Failing after 1s
govulncheck / govulncheck (./gcp/observability) (push) Failing after 1s
govulncheck / govulncheck (./security/advancedtls) (push) Failing after 1s
govulncheck / govulncheck (./stats/opencensus) (push) Failing after 1s
Stale bot / stale (push) Failing after 1s
Some checks failed
codecov / upload (push) Failing after 13m59s
CodeQL / Analyze (push) Failing after 1s
Testing / vet-proto (push) Failing after 1s
Testing / tests (arm, latest) (push) Waiting to run
Testing / extras (latest) (push) Failing after 1s
Testing / static checks (latest-1) (push) Failing after 1s
Testing / tests (-race, latest) (push) Failing after 1s
Testing / tests (i386, latest) (push) Failing after 1s
Testing / tests (latest) (push) Failing after 1s
Testing / tests (latest-1) (push) Failing after 1s
Lock Threads / lock (push) Failing after 1s
govulncheck / govulncheck (.) (push) Failing after 1s
govulncheck / govulncheck (./cmd/protoc-gen-go-grpc) (push) Failing after 1s
govulncheck / govulncheck (./gcp/observability) (push) Failing after 1s
govulncheck / govulncheck (./security/advancedtls) (push) Failing after 1s
govulncheck / govulncheck (./stats/opencensus) (push) Failing after 1s
Stale bot / stale (push) Failing after 1s
This commit is contained in:
109
test/clienttester.go
Normal file
109
test/clienttester.go
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2022 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/http2"
|
||||
)
|
||||
|
||||
var (
|
||||
clientPreface = []byte(http2.ClientPreface)
|
||||
)
|
||||
|
||||
func newClientTester(t *testing.T, conn net.Conn) *clientTester {
|
||||
ct := &clientTester{
|
||||
t: t,
|
||||
conn: conn,
|
||||
}
|
||||
ct.fr = http2.NewFramer(conn, conn)
|
||||
ct.greet()
|
||||
return ct
|
||||
}
|
||||
|
||||
type clientTester struct {
|
||||
t *testing.T
|
||||
conn net.Conn
|
||||
fr *http2.Framer
|
||||
}
|
||||
|
||||
// greet() performs the necessary steps for http2 connection establishment on
|
||||
// the server side.
|
||||
func (ct *clientTester) greet() {
|
||||
ct.wantClientPreface()
|
||||
ct.wantSettingsFrame()
|
||||
ct.writeSettingsFrame()
|
||||
ct.writeSettingsAck()
|
||||
|
||||
for {
|
||||
f, err := ct.fr.ReadFrame()
|
||||
if err != nil {
|
||||
ct.t.Errorf("error reading frame from client side: %v", err)
|
||||
}
|
||||
switch f := f.(type) {
|
||||
case *http2.SettingsFrame:
|
||||
if f.IsAck() { // HTTP/2 handshake completed.
|
||||
return
|
||||
}
|
||||
default:
|
||||
ct.t.Errorf("during greet, unexpected frame type %T", f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ct *clientTester) wantClientPreface() {
|
||||
preface := make([]byte, len(clientPreface))
|
||||
if _, err := io.ReadFull(ct.conn, preface); err != nil {
|
||||
ct.t.Errorf("Error at server-side while reading preface from client. Err: %v", err)
|
||||
}
|
||||
if !bytes.Equal(preface, clientPreface) {
|
||||
ct.t.Errorf("received bogus greeting from client %q", preface)
|
||||
}
|
||||
}
|
||||
|
||||
func (ct *clientTester) wantSettingsFrame() {
|
||||
frame, err := ct.fr.ReadFrame()
|
||||
if err != nil {
|
||||
ct.t.Errorf("error reading initial settings frame from client: %v", err)
|
||||
}
|
||||
_, ok := frame.(*http2.SettingsFrame)
|
||||
if !ok {
|
||||
ct.t.Errorf("initial frame sent from client is not a settings frame, type %T", frame)
|
||||
}
|
||||
}
|
||||
|
||||
func (ct *clientTester) writeSettingsFrame() {
|
||||
if err := ct.fr.WriteSettings(); err != nil {
|
||||
ct.t.Fatalf("Error writing initial SETTINGS frame from client to server: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (ct *clientTester) writeSettingsAck() {
|
||||
if err := ct.fr.WriteSettingsAck(); err != nil {
|
||||
ct.t.Fatalf("Error writing ACK of client's SETTINGS: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (ct *clientTester) writeGoAway(maxStreamID uint32, code http2.ErrCode, debugData []byte) {
|
||||
if err := ct.fr.WriteGoAway(maxStreamID, code, debugData); err != nil {
|
||||
ct.t.Fatalf("Error writing GOAWAY: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user