(t *testing.T)
| 1518 | } |
| 1519 | |
| 1520 | func (s) TestClientHonorsConnectContext(t *testing.T) { |
| 1521 | // Create a server that will not send a preface. |
| 1522 | lis, err := net.Listen("tcp", "localhost:0") |
| 1523 | if err != nil { |
| 1524 | t.Fatalf("Error while listening: %v", err) |
| 1525 | } |
| 1526 | defer lis.Close() |
| 1527 | go func() { // Launch the misbehaving server. |
| 1528 | sconn, err := lis.Accept() |
| 1529 | if err != nil { |
| 1530 | t.Errorf("Error while accepting: %v", err) |
| 1531 | return |
| 1532 | } |
| 1533 | defer sconn.Close() |
| 1534 | if _, err := io.ReadFull(sconn, make([]byte, len(clientPreface))); err != nil { |
| 1535 | t.Errorf("Error while reading client preface: %v", err) |
| 1536 | return |
| 1537 | } |
| 1538 | sfr := http2.NewFramer(sconn, sconn) |
| 1539 | // Do not write a settings frame, but read from the conn forever. |
| 1540 | for { |
| 1541 | if _, err := sfr.ReadFrame(); err != nil { |
| 1542 | return |
| 1543 | } |
| 1544 | } |
| 1545 | }() |
| 1546 | |
| 1547 | // Test context cancellation. |
| 1548 | timeBefore := time.Now() |
| 1549 | connectCtx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 1550 | time.AfterFunc(100*time.Millisecond, cancel) |
| 1551 | |
| 1552 | parent := channelzSubChannel(t) |
| 1553 | copts := ConnectOptions{ |
| 1554 | ChannelzParent: parent, |
| 1555 | BufferPool: mem.DefaultBufferPool(), |
| 1556 | } |
| 1557 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 1558 | defer cancel() |
| 1559 | _, err = NewHTTP2Client(connectCtx, ctx, resolver.Address{Addr: lis.Addr().String()}, copts, func(GoAwayInfo) {}) |
| 1560 | if err == nil { |
| 1561 | t.Fatalf("NewHTTP2Client() returned successfully; wanted error") |
| 1562 | } |
| 1563 | t.Logf("NewHTTP2Client() = _, %v", err) |
| 1564 | if time.Since(timeBefore) > 3*time.Second { |
| 1565 | t.Fatalf("NewHTTP2Client returned > 2.9s after context cancellation") |
| 1566 | } |
| 1567 | |
| 1568 | // Test context deadline. |
| 1569 | connectCtx, cancel = context.WithTimeout(context.Background(), 100*time.Millisecond) |
| 1570 | defer cancel() |
| 1571 | _, err = NewHTTP2Client(connectCtx, ctx, resolver.Address{Addr: lis.Addr().String()}, copts, func(GoAwayInfo) {}) |
| 1572 | if err == nil { |
| 1573 | t.Fatalf("NewHTTP2Client() returned successfully; wanted error") |
| 1574 | } |
| 1575 | t.Logf("NewHTTP2Client() = _, %v", err) |
| 1576 | } |
| 1577 |
nothing calls this directly
no test coverage detected