(t *testing.T)
| 706 | } |
| 707 | |
| 708 | func TestParallelShortConnection(t *testing.T) { |
| 709 | ln := createTestTCPListener(t) |
| 710 | defer ln.Close() |
| 711 | address := ln.Addr().String() |
| 712 | |
| 713 | var received int64 |
| 714 | el, err := NewEventLoop(func(ctx context.Context, connection Connection) error { |
| 715 | data, err := connection.Reader().Next(connection.Reader().Len()) |
| 716 | atomic.AddInt64(&received, int64(len(data))) |
| 717 | if err != nil { |
| 718 | return err |
| 719 | } |
| 720 | // t.Logf("conn[%s] received: %d, active: %v", connection.RemoteAddr(), len(data), connection.IsActive()) |
| 721 | return nil |
| 722 | }) |
| 723 | MustNil(t, err) |
| 724 | go func() { |
| 725 | el.Serve(ln) |
| 726 | }() |
| 727 | defer el.Shutdown(context.Background()) |
| 728 | |
| 729 | conns := 100 |
| 730 | sizePerConn := 1024 |
| 731 | totalSize := conns * sizePerConn |
| 732 | var wg sync.WaitGroup |
| 733 | for i := 0; i < conns; i++ { |
| 734 | wg.Add(1) |
| 735 | go func() { |
| 736 | defer wg.Done() |
| 737 | conn, err := DialConnection("tcp", address, time.Second) |
| 738 | MustNil(t, err) |
| 739 | n, err := conn.Writer().WriteBinary(make([]byte, sizePerConn)) |
| 740 | MustNil(t, err) |
| 741 | MustTrue(t, n == sizePerConn) |
| 742 | err = conn.Writer().Flush() |
| 743 | MustNil(t, err) |
| 744 | err = conn.Close() |
| 745 | MustNil(t, err) |
| 746 | }() |
| 747 | } |
| 748 | wg.Wait() |
| 749 | |
| 750 | t0 := time.Now() |
| 751 | for atomic.LoadInt64(&received) < int64(totalSize) { |
| 752 | time.Sleep(time.Millisecond) |
| 753 | if time.Since(t0) > 100*time.Millisecond { // max wait 100ms |
| 754 | break |
| 755 | } |
| 756 | } |
| 757 | Equal(t, atomic.LoadInt64(&received), int64(totalSize)) |
| 758 | } |
| 759 | |
| 760 | func TestConnectionServerClose(t *testing.T) { |
| 761 | ln := createTestTCPListener(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…